/*
 * case.cpp
 *
 *  Created on: 11-09-2012
 *      Author: mith
 */

#include "case_PAM_Vtg.h"
// MY HEADERS
#include"mros-v42.h"

namespace case_PAM_Vtg
{
debug deb;
global glob;

// *******************************************************************************************  //
// *** START OF THE COPY *** START OF THE COPY *** START OF THE COPY *** START OF THE COPY ***
// *******************************************************************************************  //

#define Sqrt sqrt
#define Power pow

/*
 *********************************************************
 ******************** Structures *************************
 *********************************************************
*/

struct parameters {
	double n;
	double t;
	double tPrim;
	double U;
	double V;
	double h;
	double epsilonF;
	double beta;

	double tF;
	double gFg;
	double Vint;
	double alpha; // extra parametr; set 1

	unsigned int L;
};

struct variables {
	double lnF;
	double lmF;
	double nF;			// ok
	double mu;			// ok
	double mF;			// ok
	double dF;			// ok

	double chiup;
	double chidown;
	double lchiup;
	double lchidown;

    double Energy;
	double magnetization;			// ok
 };

/*
 *********************************************************
 ***************** Small useful functions ****************
 *********************************************************
*/

inline void clear(parameters &p) {
	p.n = p.t = p.tPrim = p.U = p.V = p.h = p.epsilonF = p.beta = 0.;
	p.tF = p.gFg = p.Vint = p.alpha = 0.;
	p.L = 0;
}

inline void clear(variables &v) {
	v.lnF = v.lmF = v.nF = v.mu = v.mF = v.dF = 0.;
	v.chiup = v.chidown = v.lchiup = v.lchidown = 0.;
	v.Energy = v.magnetization = 0.;
}

inline void addTo(const variables &q, variables &v, double d=1.) {
	v.lnF += q.lnF*d;
	v.lmF += q.lmF*d;
	v.nF += q.nF*d;
	v.mu += q.mu*d;
	v.mF += q.mF*d;
	v.dF += q.dF*d;
	v.chiup += q.chiup*d;
	v.chidown += q.chidown*d;
	v.lchiup += q.lchiup*d;
	v.lchidown += q.lchidown*d;
	v.Energy += q.Energy*d;
	v.magnetization += q.magnetization*d;
}

inline void copyTo(variables &v, const variables &q, double d=1.) {
	v.lnF = q.lnF*d;
	v.lmF = q.lmF*d;
	v.nF = q.nF*d;
	v.mu = q.mu*d;
	v.mF = q.mF*d;
	v.dF = q.dF*d;
	v.chiup = q.chiup*d;
	v.chidown = q.chidown*d;
	v.lchiup = q.lchiup*d;
	v.lchidown = q.lchidown*d;
	v.Energy = q.Energy*d;
	v.magnetization = q.magnetization*d;
}

inline void copyTo(parameters &v, const parameters &q) {
	v.n = q.n;
	v.t = q.t;
	v.tPrim = q.tPrim;
	v.U = q.U;
	v.V = q.V;
	v.h = q.h;
	v.epsilonF = q.epsilonF;
	v.beta = q.beta;
	v.tF = q.tF;
	v.gFg = q.gFg;
	v.Vint = q.Vint;
	v.alpha = q.alpha;
	v.L = q.L;
}

inline double abs(double a) {
	if(a<0) a=-a;
	return a;
}

/*
 *********************************************************
 ***************** CLASS Functions ***********************
 *********************************************************
*/

class Func {
private:
	parameters p; // parameters
	variables v; // variables
	double nF, dF, mF, mu, lnF, lmF, chiup, chidown, lchiup, lchidown; // contractions

	// Abbreviations - dependend on kx, ky
	double gammak;
	double etak;

public:
	double Eup[2];
	double dEupdlnF[2];
	double dEupdlmF[2];
	double dEupdchiup[2];
	double dEupdchidown[2];
	double dEupdlchiup[2];
	double dEupdq[2];
	double dEupdq2[2];

	double Edown[2];
	double dEdowndlnF[2];
	double dEdowndlmF[2];
	double dEdowndchiup[2];
	double dEdowndchidown[2];
	double dEdowndlchidown[2];
	double dEdowndq[2];
	double dEdowndq2[2];

	double qup;
	double dqupdnF;
	double dqupdmF;
	double dqupddF;
	double q2up;
	double dq2updnF;
	double dq2updmF;
	double dq2upddF;

	double qdown;
	double dqdowndnF;
	double dqdowndmF;
	double dqdownddF;
	double q2down;
	double dq2downdnF;
	double dq2downdmF;
	double dq2downddF;

	Func(const parameters &p, const variables &v) {
		set(p, v);
		//refresh();
	}

	void set(const parameters &p, const variables &v) {
		copyTo(this->p, p);
		copyTo(this->v, v);
		refresh();
	}

	void set(const parameters &p) {
		copyTo(this->p, p);
		refresh();
	}

	// Gutzwiller
	double fq(int s);
	double fdqdnF(int s);
	double fdqdmF(int s);
	double fdqddF(int s);
	double fq2(int s);
	double fdq2dnF(int s);
	double fdq2dmF(int s);
	double fdq2ddF(int s);

    // Energy
    double fEup(double epsilonk, double etak, int l);
    double fdEupdlnF(double epsilonk, double etak, int l);
    double fdEupdlmF(double epsilonk, double etak, int l);
    double fdEupdq(double epsilonk, double etak, int l);
    double fdEupdq2(double epsilonk, double etak, int l);
    double fdEupdchiup(double epsilonk, double etak, int l);
    double fdEupdchidown(double epsilonk, double etak, int l);
    double fdEupdlchiup(double epsilonk, double etak, int l);

    double fEdown(double epsilonk, double etak, int l);
    double fdEdowndlnF(double epsilonk, double etak, int l);
    double fdEdowndlmF(double epsilonk, double etak, int l);
    double fdEdowndq(double epsilonk, double etak, int l);
    double fdEdowndq2(double epsilonk, double etak, int l);
    double fdEdowndchiup(double epsilonk, double etak, int l);
    double fdEdowndchidown(double epsilonk, double etak, int l);
    double fdEdowndlchidown(double epsilonk, double etak, int l);


	// REFRESH
	void refresh() {
		nF = v.nF;
		dF = v.dF;
		mF = v.mF;
		mu = v.mu;
		lnF = v.lnF;
		lmF = v.lmF;
		chiup = v.chiup;
		chidown = v.chidown;
		lchiup = v.lchiup;
		lchidown = v.lchidown;

		// obliczam funkcje Gutzwillara i poszczegolne pochodne
		qup		= fq(1);
		dqupdnF = fdqdnF(1);
		dqupdmF = fdqdmF(1);
		dqupddF = fdqddF(1);
		q2up	= fq2(1);
		dq2updnF = fdq2dnF(1);
		dq2updmF = fdq2dmF(1);
		dq2upddF = fdq2ddF(1);

		qdown		= fq(-1);
		dqdowndnF = fdqdnF(-1);
		dqdowndmF = fdqdmF(-1);
		dqdownddF = fdqddF(-1);
		q2down	= fq2(-1);
		dq2downdnF = fdq2dnF(-1);
		dq2downdmF = fdq2dmF(-1);
		dq2downddF = fdq2ddF(-1);

		// zeby pozniej mozna bylo wypisac
		glob.qup =  qup;
		glob.qdown = qdown;
		glob.q2up =  q2up;
		glob.q2down = q2down;
	}

	//REFRESH XY
	void refresh(double kx, double ky) {
		gammak = 2.*(cos(kx) + cos(ky));
		etak = 4.*cos(kx)*cos(ky);
		refresh();

		for(int i=0; i<2; i++) { // 2 families
			Eup[i] 	  = fEup(gammak, etak, 1-2*i);
			dEupdlnF[i] = fdEupdlnF(gammak, etak, 1-2*i);
			dEupdlmF[i] = fdEupdlmF(gammak, etak, 1-2*i);
			dEupdq[i]   = fdEupdq(gammak, etak, 1-2*i);
			dEupdq2[i]   = fdEupdq2(gammak, etak, 1-2*i);
			dEupdchiup[i] = fdEupdchiup(gammak, etak, 1-2*i);
			dEupdchidown[i] = fdEupdchidown(gammak, etak, 1-2*i);
			dEupdlchiup[i] = fdEupdlchiup(gammak, etak, 1-2*i);

			Edown[i] 	  = fEdown(gammak, etak, 1-2*i);
			dEdowndlnF[i] = fdEdowndlnF(gammak, etak, 1-2*i);
			dEdowndlmF[i] = fdEdowndlmF(gammak, etak, 1-2*i);
			dEdowndq[i]   = fdEdowndq(gammak, etak, 1-2*i);
			dEdowndq2[i]   = fdEdowndq2(gammak, etak, 1-2*i);
			dEdowndchiup[i] = fdEdowndchiup(gammak, etak, 1-2*i);
			dEdowndchidown[i] = fdEdowndchidown(gammak, etak, 1-2*i);
			dEdowndlchidown[i] = fdEdowndlchidown(gammak, etak, 1-2*i);

		}
	}
};


/////////////////
///////////////// FullSimplify
/////////////////

double Func::fq(int s) {
	return (2.*Power(dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))),2))/
			   ((nF + mF*s)*(1 - 0.5*(nF + mF*s)));
}

double Func::fdqdnF(int s) {
	return ((dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))))*
		     (4.*(nF + mF*s)*(1 - 0.5*(nF + mF*s))*((0.25*dF)/Sqrt(-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s) +
		          (0.25 + 0.75*Power(dF,2) - 0.5*nF - 0.25*mF*s)/Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))) +
		       1.*(nF + mF*s)*(dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))) -
		       2.*(1 - 0.5*(nF + mF*s))*(dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) +
		          Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))))))/(Power(nF + mF*s,2)*Power(1 - 0.5*(nF + mF*s),2));
}

double Func::fdqdmF(int s) {
	return ((dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))))*
		     (4.*(nF + mF*s)*(1 - 0.5*(nF + mF*s))*((-0.25*dF*s)/Sqrt(-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s) +
		          (0.25*(1 + Power(dF,2) - nF)*s)/Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))) +
		       1.*s*(nF + mF*s)*(dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))) -
		       2.*s*(1 - 0.5*(nF + mF*s))*(dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) +
		          Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))))))/(Power(nF + mF*s,2)*Power(1 - 0.5*(nF + mF*s),2));
}

double Func::fdqddF(int s) {
	return (4.*(-(Power(dF,2)/Sqrt(-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s)) + Sqrt(-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s) +
		       (dF*(-1. - 2.*Power(dF,2) + 1.5*nF + 0.5*mF*s))/Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s))))*
		     (dF*Sqrt(-Power(dF,2) + 0.5*nF - 0.5*mF*s) + Sqrt((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))))/
		   ((nF + mF*s)*(1 - 0.5*(nF + mF*s)));
}

double Func::fq2(int s) {
//	return 0;
	return Power((2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/(nF - 1.*mF*s) +
		    (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/
		     (-2. + 1.*nF - 1.*mF*s),2);
}

double Func::fdq2dnF(int s) {
//	return 0;
	return 2*((2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/(nF - 1.*mF*s) +
		     (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/
		      (-2. + 1.*nF - 1.*mF*s))*((-2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/
		      Power(nF - 1.*mF*s,2) - (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/
		          ((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/Power(2. - 1.*nF + 1.*mF*s,2) -
		     (5.656854249492381*dF*(-0.25*Power(nF,2) + 0.5*mF*nF*s + mF*s*(-1. + 0.75*mF*s) + Power(dF,2)*(-1. + 1.*nF + 1.*mF*s)))/
		      (Power(2. - 1.*nF - 1.*mF*s,2)*(nF - 1.*mF*s)*Power(nF + mF*s,2)*
		        Sqrt((-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))) +
		     (Power(dF,4)*(5.656854249492381 - 5.656854249492381*nF - 5.656854249492381*mF*s) +
		        Power(nF,2)*(-1.4142135623730951 + 1.4142135623730951*mF*s) +
		        Power(mF,2)*Power(s,2)*(-1.4142135623730951 + 1.4142135623730951*mF*s) +
		        mF*nF*s*(-2.8284271247461903 + 2.8284271247461903*mF*s) +
		        Power(dF,2)*(5.656854249492381 + 4.242640687119286*Power(nF,2) - 1.4142135623730951*Power(mF,2)*Power(s,2) +
		           nF*(-5.656854249492381 + 2.8284271247461903*mF*s)))/
		      (Power(2. - 1.*nF - 1.*mF*s,2)*(-2. + 1.*nF - 1.*mF*s)*Power(nF + mF*s,2)*
		        Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))));
}

double Func::fdq2dmF(int s) {
//	return 0;
	return 2*s*((2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/(nF - 1.*mF*s) +
		     (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/
		      (-2. + 1.*nF - 1.*mF*s))*((2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/
		      Power(nF - 1.*mF*s,2) + (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/
		          ((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/Power(2. - 1.*nF + 1.*mF*s,2) -
		     (5.656854249492381*dF*(-0.75*Power(nF,2) + 0.25*Power(mF,2)*Power(s,2) + nF*(1. - 0.5*mF*s) +
		          Power(dF,2)*(-1. + 1.*nF + 1.*mF*s)))/
		      (Power(2. - 1.*nF - 1.*mF*s,2)*(nF - 1.*mF*s)*Power(nF + mF*s,2)*
		        Sqrt((-1.*Power(dF,2) + 0.5*nF - 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))) +
		     (-1.4142135623730951*Power(nF,3) + 1.4142135623730951*Power(mF,2)*Power(s,2) +
		        Power(dF,4)*(5.656854249492381 - 5.656854249492381*nF - 5.656854249492381*mF*s) +
		        Power(nF,2)*(1.4142135623730951 - 2.8284271247461903*mF*s) + mF*nF*s*(2.8284271247461903 - 1.4142135623730951*mF*s) +
		        Power(dF,2)*(5.656854249492381 + 7.0710678118654755*Power(nF,2) - 5.656854249492381*mF*s +
		           1.4142135623730951*Power(mF,2)*Power(s,2) + nF*(-11.313708498984761 + 8.485281374238571*mF*s)))/
		      (Power(2. - 1.*nF - 1.*mF*s,2)*(-2. + 1.*nF - 1.*mF*s)*Power(nF + mF*s,2)*
		        Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))));
}

double Func::fdq2ddF(int s) {
//	return 0;
	return 2*((2.8284271247461903*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/(nF - 1.*mF*s) +
		     (2.8284271247461903*Power(dF,2)*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/
		      ((nF - 1.*mF*s)*(Power(dF,2) - 0.5*nF + 0.5*mF*s)) +
		     (dF*(5.656854249492381 + 11.313708498984761*Power(dF,2) - 8.485281374238571*nF - 2.8284271247461903*mF*s))/
		      ((-2. + 1.*nF - 1.*mF*s)*(nF + mF*s)*(-2. + 1.*nF + 1.*mF*s)*
		        Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))*
		   ((2.8284271247461903*dF*Sqrt(-((Power(dF,2) - 0.5*nF + 0.5*mF*s)/((nF + mF*s)*(1 - 0.5*(nF + mF*s))))))/(nF - 1.*mF*s) +
		     (2.8284271247461903*Sqrt(((1 + Power(dF,2) - nF)*(-Power(dF,2) + 0.5*(nF + mF*s)))/((nF + mF*s)*(1 - 0.5*(nF + mF*s)))))/
		      (-2. + 1.*nF - 1.*mF*s));
}
////////////////////////////////////////////////////////////////////////////

double Func::fEup(double gammak, double eta, int l) {
	return (-lmF - lnF - 2*mu + p.epsilonF - p.h - p.gFg*p.h + etak*p.tPrim +
		     gammak*(-lchiup + p.t + p.tF*(-(chidown*(chidown + 2*chiup)*q2up) + qup)) -
		     l*Sqrt(4*(-((mu + p.h - gammak*p.t - etak*p.tPrim)*
		              (lmF + lnF + mu - p.epsilonF + p.gFg*p.h + gammak*(lchiup + chidown*(chidown + 2*chiup)*p.tF*q2up))) +
		           (Power(p.V,2) + gammak*(p.tF*(mu + p.h - gammak*p.t - etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*qup) +
		        Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
		          gammak*(lchiup - p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup),2)))/2.;
}

double Func::fdEupdlnF(double gammak, double etak, int l) {
	return (-(l*(lmF + lnF - p.epsilonF + (-1 + p.gFg)*p.h + etak*p.tPrim)) -
		     gammak*l*(lchiup + p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup) -
		     Sqrt(4*(-((mu + p.h - gammak*p.t - etak*p.tPrim)*
		             (lmF + lnF + mu - p.epsilonF + p.gFg*p.h + gammak*(lchiup + chidown*(chidown + 2*chiup)*p.tF*q2up))) +
		          (Power(p.V,2) + gammak*(p.tF*(mu + p.h - gammak*p.t - etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*qup) +
		       Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
		         gammak*(lchiup - p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup),2)))/
		   (2.*Sqrt(4*(-((mu + p.h - gammak*p.t - etak*p.tPrim)*
		             (lmF + lnF + mu - p.epsilonF + p.gFg*p.h + gammak*(lchiup + chidown*(chidown + 2*chiup)*p.tF*q2up))) +
		          (Power(p.V,2) + gammak*(p.tF*(mu + p.h - gammak*p.t - etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*qup) +
		       Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
		         gammak*(lchiup - p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup),2)));
}

double Func::fdEupdlmF(double gammak, double etak, int l) {
	return (-(l*(lmF + lnF - p.epsilonF + (-1 + p.gFg)*p.h + etak*p.tPrim)) -
		     gammak*l*(lchiup + p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup) -
		     Sqrt(4*(-((mu + p.h - gammak*p.t - etak*p.tPrim)*
		             (lmF + lnF + mu - p.epsilonF + p.gFg*p.h + gammak*(lchiup + chidown*(chidown + 2*chiup)*p.tF*q2up))) +
		          (Power(p.V,2) + gammak*(p.tF*(mu + p.h - gammak*p.t - etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*qup) +
		       Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
		         gammak*(lchiup - p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup),2)))/
		   (2.*Sqrt(4*(-((mu + p.h - gammak*p.t - etak*p.tPrim)*
		             (lmF + lnF + mu - p.epsilonF + p.gFg*p.h + gammak*(lchiup + chidown*(chidown + 2*chiup)*p.tF*q2up))) +
		          (Power(p.V,2) + gammak*(p.tF*(mu + p.h - gammak*p.t - etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*qup) +
		       Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
		         gammak*(lchiup - p.t + chidown*(chidown + 2*chiup)*p.tF*q2up - p.tF*qup),2)));
}

double Func::fdEupdq(double gammak, double etak, int l) {
	return (gammak*p.tF + (l*(-2*Power(p.V,2) + gammak*(lmF*p.tF + lnF*p.tF - p.epsilonF*p.tF - p.h*p.tF + p.gFg*p.h*p.tF +
            etak*p.tF*p.tPrim - 4*p.V*p.Vint) + Power(gammak,2)*
          (lchiup*p.tF + p.t*p.tF - 2*Power(p.Vint,2) + Power(chidown,2)*Power(p.tF,2)*q2up +
            2*chidown*chiup*Power(p.tF,2)*q2up - Power(p.tF,2)*qup)))/
     Sqrt(Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
         gammak*(lchiup - p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup),2) +
       4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF - lnF*p.h - mu*p.h + p.epsilonF*p.h - mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
          etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim + etak*p.gFg*p.h*p.tPrim -
          lmF*(mu + p.h - etak*p.tPrim) + Power(p.V,2)*qup +
          gammak*(lmF*p.t + lnF*p.t + mu*p.t - p.epsilonF*p.t + p.gFg*p.h*p.t - lchiup*(mu + p.h - etak*p.tPrim) -
             Power(chidown,2)*mu*p.tF*q2up - 2*chidown*chiup*mu*p.tF*q2up - Power(chidown,2)*p.h*p.tF*q2up -
             2*chidown*chiup*p.h*p.tF*q2up + Power(chidown,2)*etak*p.tF*p.tPrim*q2up +
             2*chidown*chiup*etak*p.tF*p.tPrim*q2up + mu*p.tF*qup + p.h*p.tF*qup - etak*p.tF*p.tPrim*qup +
             2*p.V*p.Vint*qup) + Power(gammak,2)*(lchiup*p.t + Power(chidown,2)*p.t*p.tF*q2up +
             2*chidown*chiup*p.t*p.tF*q2up - p.t*p.tF*qup + Power(p.Vint,2)*qup))))/2.;
}

double Func::fdEupdq2(double gammak, double etak, int l) {
	return (chidown*gammak*p.tF*(-chidown - 2*chiup - ((chidown + 2*chiup)*l*
	          (lmF + lnF - p.epsilonF - p.h + p.gFg*p.h + etak*p.tPrim +
	            gammak*(lchiup + p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup)))/
	        Sqrt(Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
	            gammak*(lchiup - p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup),2) +
	          4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF - lnF*p.h - mu*p.h + p.epsilonF*p.h - mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	             etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim + etak*p.gFg*p.h*p.tPrim -
	             lmF*(mu + p.h - etak*p.tPrim) + Power(p.V,2)*qup +
	             gammak*(lmF*p.t + lnF*p.t + mu*p.t - p.epsilonF*p.t + p.gFg*p.h*p.t - lchiup*(mu + p.h - etak*p.tPrim) -
	                Power(chidown,2)*mu*p.tF*q2up - 2*chidown*chiup*mu*p.tF*q2up - Power(chidown,2)*p.h*p.tF*q2up -
	                2*chidown*chiup*p.h*p.tF*q2up + Power(chidown,2)*etak*p.tF*p.tPrim*q2up +
	                2*chidown*chiup*etak*p.tF*p.tPrim*q2up + mu*p.tF*qup + p.h*p.tF*qup - etak*p.tF*p.tPrim*qup +
	                2*p.V*p.Vint*qup) + Power(gammak,2)*
	              (lchiup*p.t + Power(chidown,2)*p.t*p.tF*q2up + 2*chidown*chiup*p.t*p.tF*q2up - p.t*p.tF*qup +
	                Power(p.Vint,2)*qup)))))/2.;
}

double Func::fdEupdchiup(double gammak, double etak, int l) {
	return chidown*gammak*p.tF*q2up*(-1 - (l*(lmF + lnF - p.epsilonF - p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchiup + p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup)))/
	      Sqrt(Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
	          gammak*(lchiup - p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup),2) +
	        4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF - lnF*p.h - mu*p.h + p.epsilonF*p.h - mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim + etak*p.gFg*p.h*p.tPrim -
	           lmF*(mu + p.h - etak*p.tPrim) + Power(p.V,2)*qup +
	           gammak*(lmF*p.t + lnF*p.t + mu*p.t - p.epsilonF*p.t + p.gFg*p.h*p.t - lchiup*(mu + p.h - etak*p.tPrim) -
	              Power(chidown,2)*mu*p.tF*q2up - 2*chidown*chiup*mu*p.tF*q2up - Power(chidown,2)*p.h*p.tF*q2up -
	              2*chidown*chiup*p.h*p.tF*q2up + Power(chidown,2)*etak*p.tF*p.tPrim*q2up +
	              2*chidown*chiup*etak*p.tF*p.tPrim*q2up + mu*p.tF*qup + p.h*p.tF*qup - etak*p.tF*p.tPrim*qup +
	              2*p.V*p.Vint*qup) + Power(gammak,2)*(lchiup*p.t + Power(chidown,2)*p.t*p.tF*q2up +
	              2*chidown*chiup*p.t*p.tF*q2up - p.t*p.tF*qup + Power(p.Vint,2)*qup))));
}

double Func::fdEupdchidown(double gammak, double etak, int l) {
	return gammak*p.tF*q2up*(-chidown - chiup - ((chidown + chiup)*l*
	        (lmF + lnF - p.epsilonF - p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchiup + p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup)))/
	      Sqrt(Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
	          gammak*(lchiup - p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup),2) +
	        4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF - lnF*p.h - mu*p.h + p.epsilonF*p.h - mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim + etak*p.gFg*p.h*p.tPrim -
	           lmF*(mu + p.h - etak*p.tPrim) + Power(p.V,2)*qup +
	           gammak*(lmF*p.t + lnF*p.t + mu*p.t - p.epsilonF*p.t + p.gFg*p.h*p.t - lchiup*(mu + p.h - etak*p.tPrim) -
	              Power(chidown,2)*mu*p.tF*q2up - 2*chidown*chiup*mu*p.tF*q2up - Power(chidown,2)*p.h*p.tF*q2up -
	              2*chidown*chiup*p.h*p.tF*q2up + Power(chidown,2)*etak*p.tF*p.tPrim*q2up +
	              2*chidown*chiup*etak*p.tF*p.tPrim*q2up + mu*p.tF*qup + p.h*p.tF*qup - etak*p.tF*p.tPrim*qup +
	              2*p.V*p.Vint*qup) + Power(gammak,2)*(lchiup*p.t + Power(chidown,2)*p.t*p.tF*q2up +
	              2*chidown*chiup*p.t*p.tF*q2up - p.t*p.tF*qup + Power(p.Vint,2)*qup))));
}

double Func::fdEupdlchiup(double gammak, double etak, int l) {
	return (gammak*(-1 - (l*(lmF + lnF - p.epsilonF - p.h + p.gFg*p.h + etak*p.tPrim +
            gammak*(lchiup + p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup)))/
        Sqrt(Power(lmF + lnF + 2*mu - p.epsilonF + p.h + p.gFg*p.h - etak*p.tPrim +
            gammak*(lchiup - p.t + Power(chidown,2)*p.tF*q2up + 2*chidown*chiup*p.tF*q2up - p.tF*qup),2) +
          4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF - lnF*p.h - mu*p.h + p.epsilonF*p.h - mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
             etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim + etak*p.gFg*p.h*p.tPrim -
             lmF*(mu + p.h - etak*p.tPrim) + Power(p.V,2)*qup +
             gammak*(lmF*p.t + lnF*p.t + mu*p.t - p.epsilonF*p.t + p.gFg*p.h*p.t - lchiup*(mu + p.h - etak*p.tPrim) -
                Power(chidown,2)*mu*p.tF*q2up - 2*chidown*chiup*mu*p.tF*q2up - Power(chidown,2)*p.h*p.tF*q2up -
                2*chidown*chiup*p.h*p.tF*q2up + Power(chidown,2)*etak*p.tF*p.tPrim*q2up +
                2*chidown*chiup*etak*p.tF*p.tPrim*q2up + mu*p.tF*qup + p.h*p.tF*qup - etak*p.tF*p.tPrim*qup +
                2*p.V*p.Vint*qup) + Power(gammak,2)*
              (lchiup*p.t + Power(chidown,2)*p.t*p.tF*q2up + 2*chidown*chiup*p.t*p.tF*q2up - p.t*p.tF*qup +
                Power(p.Vint,2)*qup)))))/2.;
}

////////////////////////////////////////////////////////////////////////////

double Func::fEdown(double gammak, double etak, int l) {
	return (lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
		     gammak*(-lchidown + p.t + p.tF*(-(chiup*(2*chidown + chiup)*q2down) + qdown)) -
		     l*Sqrt(4*((-mu + p.h + gammak*p.t + etak*p.tPrim)*
		            (-lmF + lnF + mu - p.epsilonF - p.gFg*p.h + gammak*(lchidown + chiup*(2*chidown + chiup)*p.tF*q2down)) +
		           (Power(p.V,2) + gammak*(mu*p.tF - p.tF*(p.h + gammak*p.t + etak*p.tPrim) + 2*p.V*p.Vint + gammak*Power(p.Vint,2)))*
		            qdown) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
		          gammak*(-lchidown + p.t + p.tF*(-(chiup*(2*chidown + chiup)*q2down) + qdown)),2)))/2.;
}

double Func::fdEdowndlnF(double gammak, double etak, int l) {
	return (-1 - (l*(-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
	      Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
	           lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
	           gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
	              2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
	              Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
	              Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
	              2*p.V*p.Vint*qdown) + Power(gammak,2)*
	            (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
	              Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2)))/2.;
}

double Func::fdEdowndlmF(double gammak, double etak, int l) {
	return (1 + (l*(-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
	      Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
	           lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
	           gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
	              2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
	              Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
	              Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
	              2*p.V*p.Vint*qdown) + Power(gammak,2)*
	            (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
	              Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2)))/2.;
}

double Func::fdEdowndq(double gammak, double etak, int l) {
	return (gammak*p.tF + (l*(-2*Power(p.V,2) + gammak*(-(lmF*p.tF) + lnF*p.tF - p.epsilonF*p.tF + p.h*p.tF - p.gFg*p.h*p.tF +
            etak*p.tF*p.tPrim - 4*p.V*p.Vint) + Power(gammak,2)*
          (lchidown*p.tF + p.t*p.tF - 2*Power(p.Vint,2) + 2*chidown*chiup*Power(p.tF,2)*q2down +
            Power(chiup,2)*Power(p.tF,2)*q2down - Power(p.tF,2)*qdown)))/
     Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
          etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
          lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
          gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
             2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
             Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
             Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
             2*p.V*p.Vint*qdown) + Power(gammak,2)*
           (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
             Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
         gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2)))/2.;
}

double Func::fdEdowndq2(double gammak, double etak, int l) {
	return (chiup*gammak*p.tF*(-2*chidown - chiup - ((2*chidown + chiup)*l*
	          (-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
	            gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
	        Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h -
	             p.gFg*Power(p.h,2) + etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
	             lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
	             gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
	                2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
	                Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
	                Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
	                2*p.V*p.Vint*qdown) + Power(gammak,2)*
	              (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
	                Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
	            gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2))))/2.;
}

double Func::fdEdowndchiup(double gammak, double etak, int l) {
	return gammak*p.tF*q2down*(-chidown - chiup - ((chidown + chiup)*l*
	        (-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
	      Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
	           lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
	           gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
	              2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
	              Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
	              Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
	              2*p.V*p.Vint*qdown) + Power(gammak,2)*
	            (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
	              Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2)));
}

double Func::fdEdowndchidown(double gammak, double etak, int l) {
	return chiup*gammak*p.tF*q2down*(-1 - (l*(-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
	          gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
	      Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h - p.gFg*Power(p.h,2) +
	           etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
	           lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
	           gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
	              2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
	              Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
	              Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
	              2*p.V*p.Vint*qdown) + Power(gammak,2)*
	            (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
	              Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
	          gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2)));
}

double Func::fdEdowndlchidown(double gammak, double etak, int l) {
	return (gammak*(-1 - (l*(-lmF + lnF - p.epsilonF + p.h - p.gFg*p.h + etak*p.tPrim +
            gammak*(lchidown + p.t + 2*chidown*chiup*p.tF*q2down + Power(chiup,2)*p.tF*q2down - p.tF*qdown)))/
        Sqrt(4*(-(lnF*mu) - Power(mu,2) + mu*p.epsilonF + lnF*p.h + mu*p.h - p.epsilonF*p.h + mu*p.gFg*p.h -
             p.gFg*Power(p.h,2) + etak*lnF*p.tPrim + etak*mu*p.tPrim - etak*p.epsilonF*p.tPrim - etak*p.gFg*p.h*p.tPrim +
             lmF*(mu - p.h - etak*p.tPrim) + Power(p.V,2)*qdown +
             gammak*(-(lmF*p.t) + lnF*p.t + mu*p.t - p.epsilonF*p.t - p.gFg*p.h*p.t + lchidown*(-mu + p.h + etak*p.tPrim) -
                2*chidown*chiup*mu*p.tF*q2down - Power(chiup,2)*mu*p.tF*q2down + 2*chidown*chiup*p.h*p.tF*q2down +
                Power(chiup,2)*p.h*p.tF*q2down + 2*chidown*chiup*etak*p.tF*p.tPrim*q2down +
                Power(chiup,2)*etak*p.tF*p.tPrim*q2down + mu*p.tF*qdown - p.h*p.tF*qdown - etak*p.tF*p.tPrim*qdown +
                2*p.V*p.Vint*qdown) + Power(gammak,2)*
              (lchidown*p.t + 2*chidown*chiup*p.t*p.tF*q2down + Power(chiup,2)*p.t*p.tF*q2down - p.t*p.tF*qdown +
                Power(p.Vint,2)*qdown)) + Power(lmF - lnF - 2*mu + p.epsilonF + p.h + p.gFg*p.h + etak*p.tPrim +
            gammak*(-lchidown + p.t + p.tF*(-2*chidown*chiup*q2down - Power(chiup,2)*q2down + qdown)),2))))/2.;
}

/*
 *********************************************************
 ******************* CLASS Equations *********************
 *********************************************************
*/

class Equa {
private:
	parameters p; // parameters
	variables v; // variables
	Func *f;

	void onePoint(variables &y, int i, int j);

public:
	Equa(parameters &p, variables &v) : p(p), v(v) { f = new Func(p, v); }
	~Equa() { delete f; }

	void setPar(parameters &p) {
		this->p = p;
		f->set(p);
	}

	void setParVar(parameters &p, variables &v) {
		this->p = p;
		this->v = v;
		f->set(p, v);
	}

	//void run(variables &w);
	void run2(variables &w);
	void run_global(variables &w);

};

void Equa::onePoint(variables &w, int i, int j) {
	double x = (double)i*2.*M_PI/p.L;
	double y = (double)j*2.*M_PI/p.L;

	f->refresh(x, y);
	//if(DEEP_DEBUG) { f->printLambda(); }

	double Euptan[2] = { (1-tanh(p.beta*f->Eup[0]/2.))/2., (1-tanh(p.beta*f->Eup[1]/2.))/2.};
	double Edowntan[2] = { (1-tanh(p.beta*f->Edown[0]/2.))/2., (1-tanh(p.beta*f->Edown[1]/2.))/2.};

	for(int i=0; i<2; i++) {
		// up
		w.lnF += Euptan[i]*f->dEupdq[i]*f->dqupdnF + Euptan[i]*f->dEupdq2[i]*f->dq2updnF;
		w.lmF += Euptan[i]*f->dEupdq[i]*f->dqupdmF + Euptan[i]*f->dEupdq2[i]*f->dq2updmF;
		w.nF += Euptan[i]*f->dEupdlnF[i];
		w.mu += Euptan[i];
		w.mF += Euptan[i]*f->dEupdlmF[i];
		w.dF += Euptan[i]*f->dEupdq[i]*f->dqupddF + Euptan[i]*f->dEupdq2[i]*f->dq2upddF;
		w.chiup += Euptan[i]*f->dEupdlchiup[i];
		//w.chidown += 0;
		w.lchiup += Euptan[i]*f->dEupdchiup[i];
		w.lchidown += Euptan[i]*f->dEupdchidown[i];

		// down
		w.lnF += Edowntan[i]*f->dEdowndq[i]*f->dqdowndnF + Edowntan[i]*f->dEdowndq2[i]*f->dq2downdnF;
		w.lmF += Edowntan[i]*f->dEdowndq[i]*f->dqdowndmF + Edowntan[i]*f->dEdowndq2[i]*f->dq2downdmF;
		w.nF += Edowntan[i]*f->dEdowndlnF[i];
		w.mu += Edowntan[i];
		w.mF += Edowntan[i]*f->dEdowndlmF[i];
		w.dF += Edowntan[i]*f->dEdowndq[i]*f->dqdownddF + Edowntan[i]*f->dEdowndq2[i]*f->dq2downddF;
		//w.chiup += 0;
		w.chidown += Edowntan[i]*f->dEdowndlchidown[i];
		w.lchiup += Edowntan[i]*f->dEdowndchiup[i];
		w.lchidown += Edowntan[i]*f->dEdowndchidown[i];

		w.magnetization += Euptan[i] - Edowntan[i];

        // it would be safer have following code - warning: 30 is chosen arbitrarily
		if(p.beta*f->Eup[i] > 10.) { w.Energy += -exp(-p.beta*f->Eup[i])/p.beta; } // basically 0
		else if(p.beta*f->Eup[i] < -10) { w.Energy += f->Eup[i]; }
		else { w.Energy += -log(1 + exp(-p.beta*f->Eup[i]))/p.beta; }

		if(p.beta*f->Edown[i] > 10.) { w.Energy += -exp(-p.beta*f->Edown[i])/p.beta; } // basically 0
		else if(p.beta*f->Edown[i] < -10) { w.Energy += f->Edown[i]; }
		else { w.Energy += -log(1 + exp(-p.beta*f->Edown[i]))/p.beta; }
	}
}

// ***********************************************************************************  //
// *** END OF THE COPY *** END OF THE COPY *** END OF THE COPY *** END OF THE COPY ***
// ***********************************************************************************  //

void Equa::run2(variables &w)
{
	clear(w);
	variables temp; clear(temp); // temporary vector using during summation
	int max = p.L/2; // attention: L should be even!

	//int iii = 0;

/*
    // SERIAL CASE - OK
    for(int i=-max; i<max; i++) {
		for(int j=-max; j<max; j++) {
			onePoint(temp, i, j);
     	}
    }
    addTo(temp, w, 1);
    clear(temp);
*/
    // SMART WAY - ALSO OK
    // SERIAL CASE
   	// SMART WAY OF SUMMATION - I use symmetry k_x,y <-> -k_x,y
   	// * edges (4 times)
   	for(int i=1; i<max; i++) {
   		onePoint(temp, i, i);
   		onePoint(temp, max, i);
   		onePoint(temp, i, 0);
   		//iii += 12;
   	}
      addTo(temp, w, 4);
      clear(temp);
      // * interior area (8 times) - SERIAL CASE
      for(int i=1; i<max; i++) {
   		for(int j=1; j<i; j++) {
   			onePoint(temp, i, j); //iii+=8;									//	sleep(1);
        	}
   	}
   	addTo(temp, w, 8);
   	clear(temp);
   	// * missing corners
   	onePoint(w, max, max);
   	onePoint(w, max, 0);
   	onePoint(w, 0, max);
   	onePoint(w, 0, 0);
   	//iii += 4;

    //printf("%d\n", iii);

	// what was out of sumation
	double L2 = (double)(p.L*p.L);
	w.lnF /= L2;
	w.lmF /= L2;
	w.nF /= L2;
	w.mu /= L2;
	w.mF /= L2;
	w.dF /= L2;
	w.chiup /= L2;
	w.chidown /= L2;
	w.lchiup /= L2;
	w.lchidown /= L2;
    w.Energy /= L2;
    w.magnetization /= L2;

	w.lnF += v.lnF;
	w.lmF += v.lmF;
	w.nF += v.nF;
	w.mu += -p.n;
	w.mF += v.mF;
	w.dF += 2.*p.U*v.dF;
	w.chiup += 4.*v.chiup;
	w.chidown += 4.*v.chidown;
	w.lchiup += 4.*v.lchiup + 8.*p.tF*v.chidown*(f->q2down*v.chiup + f->q2up*v.chidown) + 8.*p.tF*v.chiup*v.chidown*f->q2down;
	w.lchidown += 4.*v.lchidown + 8.*p.tF*v.chiup*(f->q2down*v.chiup + f->q2up*v.chidown) + 8.*p.tF*v.chiup*v.chidown*f->q2up;

    v.Energy = w.Energy + v.lnF*v.nF + v.lmF*v.mF + p.U*v.dF*v.dF + 4.*(v.lchiup*v.chiup+v.lchidown*v.chidown) + 8.*p.tF*v.chiup*v.chidown*(f->q2down*v.chiup + f->q2up*v.chidown);
    v.magnetization = w.magnetization;

    // results
    case_PAM_Vtg::glob.Energy = v.Energy + v.mu*p.n;
    case_PAM_Vtg::glob.magnetization = v.magnetization;
	//glob.qt = f->fgt();
}

int function(const gsl_vector * x, void *params, gsl_vector * f) {

	struct parameters p;
	p.n = ((Par *) params)->n();
	p.t = ((Par *) params)->t();
	p.tPrim = ((Par *) params)->tPrim();
	p.U = ((Par *) params)->U();
	p.V = ((Par *) params)->V();
	p.h = ((Par *) params)->h();
	p.epsilonF = ((Par *) params)->epsilonF();
	p.beta = ((Par *) params)->beta();
	p.tF = ((Par *) params)->tF();
	p.gFg = ((Par *) params)->gFg();
	p.Vint = ((Par *) params)->Vint();
	p.alpha = ((Par *) params)->alpha();
	p.L = ((Par *) params)->L();

	variables v;
	v.lnF = gsl_vector_get (x, 0);
	v.lmF = gsl_vector_get (x, 1);
	v.nF = gsl_vector_get (x, 2);
	v.mu = gsl_vector_get (x, 3);
	v.mF = gsl_vector_get (x, 4);
	v.dF = gsl_vector_get (x, 5);
	v.chiup = gsl_vector_get (x, 6);
	v.chidown = gsl_vector_get (x, 7);
	v.lchiup = gsl_vector_get (x, 8);
	v.lchidown = gsl_vector_get (x, 9);

	if(DEBUG2) {
		printf("### %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e\n",
				gsl_vector_get (x, 0), gsl_vector_get (x, 1), gsl_vector_get (x, 2),
				gsl_vector_get (x, 3), gsl_vector_get (x, 4), gsl_vector_get (x, 5),
				gsl_vector_get (x, 6), gsl_vector_get (x, 7), gsl_vector_get (x, 8), gsl_vector_get (x, 9));
	}

    // It's start of the calculations

    Equa E(p, v);
    variables w;
    //E.run(w);
    //E.run_global(w);
    E.run2(w);

    // It's end of the calculations

	gsl_vector_set (f, 0, w.lnF);
	gsl_vector_set (f, 1, w.lmF);
	gsl_vector_set (f, 2, w.nF);
	gsl_vector_set (f, 3, w.mu);
	gsl_vector_set (f, 4, w.mF);
	gsl_vector_set (f, 5, w.dF);
	gsl_vector_set (f, 6, w.chiup);
	gsl_vector_set (f, 7, w.chidown);
	gsl_vector_set (f, 8, w.lchiup);
	gsl_vector_set (f, 9, w.lchidown);

	if(DEBUG2) {
		printf("### %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e %25.15e\n",
				gsl_vector_get (x, 0), gsl_vector_get (x, 1), gsl_vector_get (x, 2),
				gsl_vector_get (x, 3), gsl_vector_get (x, 4), gsl_vector_get (x, 5),
				gsl_vector_get (x, 6), gsl_vector_get (x, 7), gsl_vector_get (x, 8), gsl_vector_get (x, 9));
		printf("###  %24.15e# %25.15e# %24.15e# %24.15e# %24.15e# %24.15e# %24.15e# %24.15e# %24.15e# %24.15e# | E = %24.15e m = %24.15e\n",
			gsl_vector_get (f, 0), gsl_vector_get (f, 1), gsl_vector_get (f, 2),
			gsl_vector_get (f, 3), gsl_vector_get (f, 4), gsl_vector_get (f, 5),
			gsl_vector_get (f, 6), gsl_vector_get (f, 7), gsl_vector_get (f, 8), gsl_vector_get (f, 9),
			case_PAM_Vtg::glob.Energy, case_PAM_Vtg::glob.magnetization);
		printf("\n");
	}

    return GSL_SUCCESS;
}

// ************* CLASSES ************* //

// Par

void Par::print(FILE *file) const {
	for(int i=0; i<NtabD; i++) { fprintf(file, " %12.9f", tabD[i]); }
	for(int i=0; i<NtabI; i++) { fprintf(file, " %6d", tabI[i]); }
}

void Par::print_verboten(FILE *file) const {
	fprintf(file, "PARAMETERS: n=%f, t=%f, tPrim=%f, U=%f, V=%f, h=%f, epsilonF=%f, tF=%f, gFg=%f, Vint=%f, alpha=%f, beta=%f, L=%d\n", n(), t(), tPrim(), U(), V(), h(), epsilonF(), tF(), gFg(), Vint(), alpha(), beta(), L());
}

void Par::print_label(FILE *file) const {
	fprintf(file, "n   t   tPrim   U   V   h   epsilonF  beta   tF   gFg    Vint    alpha    L");
}

// Var

void Var::print(FILE *file) const{
	for(int i=0; i<NtabD; i++) { fprintf(file, " %12.9f", tabD[i]); }
}

void Var::print_verboten(FILE *file) const{
	fprintf(file, "VARIABLES:");
	for(int i=0; i<NtabD; i++) { fprintf(file, " %22.15e", tabD[i]); }
	fprintf(file, "\n");
}

void Var::print_label(FILE *file) const {
	fprintf(file, "  lnF          lmF          nF             mu            mF           d       chiup        chidown      lchiup      lchidown");
}

// Res

void Res::set(gsl_multiroot_fsolver *s) {
	for(int i=0; i<n; i++) {
		(*V)[i] = gsl_vector_get (s->x, i);
	}
	this->glob = case_PAM_Vtg::glob;
}

void Res::print(FILE *file) const { V->print(file); fprintf(file, "%22.15f %22.15f %12.9f %12.9f %12.9f %12.9f", glob.Energy, glob.magnetization, glob.qup, glob.qdown, glob.q2up, glob.q2down); }
void Res::print_verboten(FILE *file) const { fprintf(file, "Result: "); V->print_verboten(file); fprintf(file, "%22.15f %22.15f %22.15f %22.15f %22.15f\n", glob.Energy, glob.qup, glob.qdown, glob.q2up, glob.q2down); }
void Res::print_label(FILE *file) const { V->print_label(file); fprintf(file, "             E                       m             qup           qdown       q2up           q2down       ");}

void example() {

    // (S1) U=20; HM
    Par initPar_simple1_HM(N_PAR);
    initPar_simple1_HM.set_n(1.6);
    initPar_simple1_HM.set_t(-1.);
    initPar_simple1_HM.set_tPrim(0.25);
    initPar_simple1_HM.set_U(20.);
    initPar_simple1_HM.set_V(-1.75);
    initPar_simple1_HM.set_h(0.0);
    initPar_simple1_HM.set_epsilonF(-3.0);
    initPar_simple1_HM.set_tF(-0.0);
    initPar_simple1_HM.set_gFg(1.);
    initPar_simple1_HM.set_Vint(-0.0);
    initPar_simple1_HM.set_alpha(0.0);
    initPar_simple1_HM.set_beta(5000.);
    initPar_simple1_HM.set_L(512);
    Var initV_simple1_HM(N_VAR);
    initV_simple1_HM.set_lnF(-2.473211876462282e+00);
    initV_simple1_HM.set_lmF(7.970944301889716e-01);
    initV_simple1_HM.set_nF(7.734603340326791e-01);
    initV_simple1_HM.set_mu(-1.054582622367687e+00);
    initV_simple1_HM.set_mF(4.936234573956655e-01);
    initV_simple1_HM.set_dF(7.883688467292854e-02);
    initV_simple1_HM.set_chiup(1e-5);
    initV_simple1_HM.set_chidown(1e-5);
    initV_simple1_HM.set_lchiup(1e-12);
    initV_simple1_HM.set_lchidown(1e-12);

    // (S2) U=5; HM
    Par initPar_simple2_HM(N_PAR);
    initPar_simple2_HM.set_n(1.8);
    initPar_simple2_HM.set_t(-1.);
    initPar_simple2_HM.set_tPrim(0.00);
    initPar_simple2_HM.set_U(5.);
    initPar_simple2_HM.set_V(-1.2);
    initPar_simple2_HM.set_h(0.0);
    initPar_simple2_HM.set_epsilonF(-3.0);
    initPar_simple2_HM.set_tF(-0.0);
    initPar_simple2_HM.set_gFg(1.);
    initPar_simple2_HM.set_Vint(-0.0);
    initPar_simple2_HM.set_alpha(0.0);
    initPar_simple2_HM.set_beta(5000.);
    initPar_simple2_HM.set_L(512);
    //-0.000000  -2.388809593  0.218859331  0.982123075 -0.762438731  0.243098169  0.306716289 -0.139965294 -0.012339289 -0.000000000  0.000000000    -5.069200946835242      0.200000000000120  0.680649273  0.674692146  0.012054645  0.036935681
    Var initV_simple2_HM(N_VAR);
    initV_simple2_HM.set_lnF(-2.388809593);
    initV_simple2_HM.set_lmF(0.218859331);
    initV_simple2_HM.set_nF(0.982123075);
    initV_simple2_HM.set_mu(-0.762438731);
    initV_simple2_HM.set_mF(0.243098169);
    initV_simple2_HM.set_dF(0.306716289);
    initV_simple2_HM.set_chiup(-0.139965294);
    initV_simple2_HM.set_chidown(-0.012339289);
    initV_simple2_HM.set_lchiup(1e-12);
    initV_simple2_HM.set_lchidown(1e-12);


    // (S2) // 	V=-0.5		-- PM
    Par initPar_simple2_PM(N_PAR);
    initPar_simple2_PM.set_n(1.8);
    initPar_simple2_PM.set_t(-1.);
    initPar_simple2_PM.set_tPrim(0.);
    initPar_simple2_PM.set_U(5.);
    initPar_simple2_PM.set_V(-0.5);
    initPar_simple2_PM.set_h(0.0);
    initPar_simple2_PM.set_epsilonF(-3.0);
    initPar_simple2_PM.set_tF(-0.0);
    initPar_simple2_PM.set_gFg(1.);
    initPar_simple2_PM.set_Vint(-0.0);
    initPar_simple2_PM.set_alpha(0.0);
    initPar_simple2_PM.set_beta(5000.);
    initPar_simple2_PM.set_L(512);
    //    //0.000000  -2.557289173 -0.000000000  1.000259821 -0.444461984 -0.000000000  0.054606733 -0.115435729 -0.115435729  0.000000000  0.000000000    -4.585337419575739     -0.000000000001834  0.022673964  0.022673964  0.000046027  0.000046027
    Var initV_simple2_PM(N_VAR);
    initV_simple2_PM.set_lnF(-2.5572);
    initV_simple2_PM.set_lmF(1e-12);
    initV_simple2_PM.set_nF(1.000259);
    initV_simple2_PM.set_mu(-0.44446);
    initV_simple2_PM.set_mF(1e-12);
    initV_simple2_PM.set_dF(0.05460);
    initV_simple2_PM.set_chiup(-0.1154);
    initV_simple2_PM.set_chidown(-0.1154);
    initV_simple2_PM.set_lchiup(1e-12);
    initV_simple2_PM.set_lchidown(1e-12);

    // (S3)	// V=-1.2	-- PM
    Par initPar_simple3_PM(N_PAR);
    initPar_simple3_PM.set_n(1.8);
    initPar_simple3_PM.set_t(-1.);
    initPar_simple3_PM.set_tPrim(0.);
    initPar_simple3_PM.set_U(5.);
    initPar_simple3_PM.set_V(-1.2);
    initPar_simple3_PM.set_h(0.0);
    initPar_simple3_PM.set_epsilonF(-3.0);
    initPar_simple3_PM.set_tF(-0.0);
    initPar_simple3_PM.set_gFg(1.);
    initPar_simple3_PM.set_Vint(-0.0);
    initPar_simple3_PM.set_alpha(0.0);
    initPar_simple3_PM.set_beta(5000.);
    initPar_simple3_PM.set_L(512);
    //-0.000000  -2.377036424 -0.000000000  0.981814923 -0.877522375 -0.000000000  0.307792854 -0.063021751 -0.063021751 -0.000000000 -0.000000000    -5.056461322665133     -0.000000000003684  0.657097583  0.657097583  0.001735191  0.001735191
    Var initV_simple3_PM(N_VAR);
    initV_simple3_PM.set_lnF(-2.377036424);
    initV_simple3_PM.set_lmF(1e-12);
    initV_simple3_PM.set_nF(0.981814923);
    initV_simple3_PM.set_mu(-0.877522375);
    initV_simple3_PM.set_mF(1e-12);
    initV_simple3_PM.set_dF(0.307792854);
    initV_simple3_PM.set_chiup(-0.063021751);
    initV_simple3_PM.set_chidown(-0.063021751);
    initV_simple3_PM.set_lchiup(1e-12);
    initV_simple3_PM.set_lchidown(1e-12);

	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_simple3_PM;
	Var initV(N_VAR); initV = initV_simple3_PM;

	printf("#dochodze do punktu startowego (Vtg)\n");

//	automatic_run_U(initPar, initV, 20, 5.0, 1.0); printf("\n");
//	automatic_run_n(initPar, initV, 1.6, 1.8, 0.01); printf("\n");
//	automatic_run_V(initPar, initV, -1.75, -1.2, 0.01); printf("\n");
//	automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.01); printf("\n");

	//automatic_run_Vint(initPar, initV, -0.002, -0.0, 0.002); printf("\n");
	//automatic_run_V(initPar, initV, -0.50, -1.2, 0.01); printf("\n");

	//automatic_run_tF(initPar, initV, -0., -0.1, 0.01); printf("\n");
	//automatic_run_Vint(initPar, initV, -0.00, -1.0, 0.002); printf("\n");
	//automatic_run_h(initPar, initV, 0., 0.1, 0.01); printf("\n");
	//automatic_run_n(initPar, initV, 1.6, 2.00, 0.01); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -2.35, 0.05); printf("\n");
	//automatic_run_VtoP(initPar, initV, -1.75, -2.3, 0.01,  -12./5., -36./5.); printf("\n");
	//automatic_run_beta(initPar, initV, 500, 1, 5); printf("\n");

	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

	automatic_run_tF(initPar, initV, -0., -0.1, 0.01); printf("\n");
	automatic_run_beta(initPar, initV, 5000, 20000, 3000); printf("\n");
	automatic_run_L(initPar, initV, 512, 5000, 512); printf("\n");

    printf("Koniec\n");
}

void example_inf() {

    Par initPar_mw(N_PAR);
    initPar_mw.set_n(1.8);
    initPar_mw.set_t(-1.);
    initPar_mw.set_tPrim(0.00);
    initPar_mw.set_U(5.);
    initPar_mw.set_V(-1.2);
    initPar_mw.set_h(0.00);
    initPar_mw.set_epsilonF(-3.);
    initPar_mw.set_tF(-0.55);
    initPar_mw.set_gFg(1.);
    initPar_mw.set_Vint(-0.);
    initPar_mw.set_alpha(-0.);
    initPar_mw.set_beta(5000.);
    initPar_mw.set_L(512);
    initPar_mw.print_verboten();

	// I'm choosing start point
	Var initV(N_VAR);

	//FILE * pFile;
	//pFile = fopen("test2.txt", "w");

	// INFINITE
	Res res(N_VAR);
	RootGSL root(initPar_mw, function, res);
	printf("sdelta      "); res.print_label(); printf("\n"); fflush(stdout);
	while(1) {
	    initV.set_lnF(10.*frand()-5.);
	    initV.set_lmF(4.*frand()-2.);
	    initV.set_nF(2.*frand());
	    initV.set_mu(4.*frand()-2);
	    initV.set_mF(frand());
	    initV.set_dF(frand());
	    initV.set_chiup(2.*frand()-1.);
	    initV.set_chidown(2.*frand()-1.);
	    initV.set_lchiup(2.*frand()-1.);
	    initV.set_lchidown(2.*frand()-1.);


		if(root.Solve(initV) == GSL_SUCCESS) {
			printf("       "); root.print();printf("\n");  fflush(stdout);

		}
	}
	//fclose (pFile);
}

void run_1D() {

    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

    // (B2-0-0-0-HM) V=-1.2, h=0.0, Vint=0, tF=0, t'=0.25
    Par initPar_B_V12Vint0tF0_HM(N_PAR);
    initPar_B_V12Vint0tF0_HM.set_n(1.8);
    initPar_B_V12Vint0tF0_HM.set_t(-1.);
    initPar_B_V12Vint0tF0_HM.set_tPrim(0.25);
    initPar_B_V12Vint0tF0_HM.set_U(5.);
    initPar_B_V12Vint0tF0_HM.set_V(-1.2);
    initPar_B_V12Vint0tF0_HM.set_h(0.0);
    initPar_B_V12Vint0tF0_HM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF0_HM.set_tF(-0.0);
    initPar_B_V12Vint0tF0_HM.set_gFg(1.);
    initPar_B_V12Vint0tF0_HM.set_Vint(-0.0);
    initPar_B_V12Vint0tF0_HM.set_alpha(0.0);
    initPar_B_V12Vint0tF0_HM.set_beta(5000.);
    initPar_B_V12Vint0tF0_HM.set_L(512);
    //        -2.233439717  0.242535105  0.957803266 -0.877477471  0.257455342  0.294530643 -0.130743575 -0.005223736  0.000000000  0.000000000    -5.060748275674911      0.200000000000163  0.706205875  0.692179583  0.004533367  0.063157986
    Var initV_B_V12Vint0tF0_HM(N_VAR);
    initV_B_V12Vint0tF0_HM.set_lnF(-2.233439717);
    initV_B_V12Vint0tF0_HM.set_lmF(0.242535105);
    initV_B_V12Vint0tF0_HM.set_nF(0.957803266);
    initV_B_V12Vint0tF0_HM.set_mu(-0.877477471);
    initV_B_V12Vint0tF0_HM.set_mF(0.257455342);
    initV_B_V12Vint0tF0_HM.set_dF(0.294530643);
    initV_B_V12Vint0tF0_HM.set_chiup(-0.130743575);
    initV_B_V12Vint0tF0_HM.set_chidown(-0.005223736);
    initV_B_V12Vint0tF0_HM.set_lchiup(1e-12);
    initV_B_V12Vint0tF0_HM.set_lchidown(1e-12);

    // (B2-0-0-0-PM) V=-1.2, h=0.0, Vint=0, tF=0, t'=0.25
    Par initPar_B_V12Vint0tF0_PM(N_PAR);
    initPar_B_V12Vint0tF0_PM.set_n(1.8);
    initPar_B_V12Vint0tF0_PM.set_t(-1.);
    initPar_B_V12Vint0tF0_PM.set_tPrim(0.25);
    initPar_B_V12Vint0tF0_PM.set_U(5.);
    initPar_B_V12Vint0tF0_PM.set_V(-1.2);
    initPar_B_V12Vint0tF0_PM.set_h(0.0);
    initPar_B_V12Vint0tF0_PM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF0_PM.set_tF(-0.0);
    initPar_B_V12Vint0tF0_PM.set_gFg(1.);
    initPar_B_V12Vint0tF0_PM.set_Vint(-0.0);
    initPar_B_V12Vint0tF0_PM.set_alpha(0.0);
    initPar_B_V12Vint0tF0_PM.set_beta(5000.);
    initPar_B_V12Vint0tF0_PM.set_L(512);
    //        -2.219780009  0.000000000  0.956765407 -1.006625834  0.000000000  0.296026615 -0.054899591 -0.054899591  0.000000000  0.000000000    -5.046368791402772      0.000000000000010  0.677540789  0.677540789  0.008742181  0.008742181
    Var initV_B_V12Vint0tF0_PM(N_VAR);
    initV_B_V12Vint0tF0_PM.set_lnF(-2.219780009);
    initV_B_V12Vint0tF0_PM.set_lmF(1e-12);
    initV_B_V12Vint0tF0_PM.set_nF(0.956765407);
    initV_B_V12Vint0tF0_PM.set_mu(-1.006625834);
    initV_B_V12Vint0tF0_PM.set_mF(1e-12);
    initV_B_V12Vint0tF0_PM.set_dF(0.296026615);
    initV_B_V12Vint0tF0_PM.set_chiup(-0.054899591);
    initV_B_V12Vint0tF0_PM.set_chidown(-0.054899591);
    initV_B_V12Vint0tF0_PM.set_lchiup(1e-12);
    initV_B_V12Vint0tF0_PM.set_lchidown(1e-12);

    // (B2-0-0-01-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.1, t'=0.00
    Par initPar_B_V12Vint0tF01_SFM(N_PAR);
    initPar_B_V12Vint0tF01_SFM.set_n(1.8);
    initPar_B_V12Vint0tF01_SFM.set_t(-1.);
    initPar_B_V12Vint0tF01_SFM.set_tPrim(0.00);
    initPar_B_V12Vint0tF01_SFM.set_U(5.);
    initPar_B_V12Vint0tF01_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF01_SFM.set_h(0.0);
    initPar_B_V12Vint0tF01_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF01_SFM.set_tF(-0.1);
    initPar_B_V12Vint0tF01_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF01_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF01_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF01_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF01_SFM.set_L(512);
    //        -2.443121112  0.844733474  0.989944079 -0.662221836  0.670285765  0.273352951 -0.011967429  0.024615212 -0.000011369  0.000005528    -5.051508078101628      0.584540643064199  0.785405712  0.774634207  0.277265174  0.340393679
    Var initV_B_V12Vint0tF01_SFM(N_VAR);
    initV_B_V12Vint0tF01_SFM.set_lnF(-2.443121112);
    initV_B_V12Vint0tF01_SFM.set_lmF(0.844733474);
    initV_B_V12Vint0tF01_SFM.set_nF(0.989944079);
    initV_B_V12Vint0tF01_SFM.set_mu(-0.662221836);
    initV_B_V12Vint0tF01_SFM.set_mF(0.670285765);
    initV_B_V12Vint0tF01_SFM.set_dF(0.273352951);
    initV_B_V12Vint0tF01_SFM.set_chiup(-0.011967429);
    initV_B_V12Vint0tF01_SFM.set_chidown(0.024615212);
    initV_B_V12Vint0tF01_SFM.set_lchiup(-0.000011369);
    initV_B_V12Vint0tF01_SFM.set_lchidown(0.000005528);

    // (B2-0-0-02-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.2, t'=0.25
    Par initPar_B_V12Vint0tF02_SFM(N_PAR);
    initPar_B_V12Vint0tF02_SFM.set_n(1.8);
    initPar_B_V12Vint0tF02_SFM.set_t(-1.);
    initPar_B_V12Vint0tF02_SFM.set_tPrim(0.25);
    initPar_B_V12Vint0tF02_SFM.set_U(5.);
    initPar_B_V12Vint0tF02_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF02_SFM.set_h(0.0);
    initPar_B_V12Vint0tF02_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF02_SFM.set_tF(-0.2);
    initPar_B_V12Vint0tF02_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF02_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF02_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF02_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF02_SFM.set_L(512);
    //-0.200000  -2.275891200  0.766044434  0.970139656 -0.840481120  0.624340668  0.269737199 -0.018190714  0.032730055 -0.000098520  0.000054755    -5.029044626085287      0.533009119632198  0.792954231  0.765962498  0.166442393  0.314224619
    Var initV_B_V12Vint0tF02_SFM(N_VAR);
    initV_B_V12Vint0tF02_SFM.set_lnF(-2.275891200);
    initV_B_V12Vint0tF02_SFM.set_lmF(0.766044434);
    initV_B_V12Vint0tF02_SFM.set_nF(0.970139656);
    initV_B_V12Vint0tF02_SFM.set_mu(-0.840481120);
    initV_B_V12Vint0tF02_SFM.set_mF(0.624340668);
    initV_B_V12Vint0tF02_SFM.set_dF(0.269737199);
    initV_B_V12Vint0tF02_SFM.set_chiup(-0.018190714);
    initV_B_V12Vint0tF02_SFM.set_chidown(0.032730055);
    initV_B_V12Vint0tF02_SFM.set_lchiup(-0.000098520);
    initV_B_V12Vint0tF02_SFM.set_lchidown(0.000054755);

    // (B3-0-0-034-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.34, t'=0.00
    Par initPar_B_V12Vint0tF034_SFM(N_PAR);
    initPar_B_V12Vint0tF034_SFM.set_n(1.8);
    initPar_B_V12Vint0tF034_SFM.set_t(-1.);
    initPar_B_V12Vint0tF034_SFM.set_tPrim(0.00);
    initPar_B_V12Vint0tF034_SFM.set_U(5.);
    initPar_B_V12Vint0tF034_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF034_SFM.set_h(0.0);
    initPar_B_V12Vint0tF034_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF034_SFM.set_tF(-0.34);
    initPar_B_V12Vint0tF034_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF034_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF034_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF034_SFM.set_beta(25000.);
    initPar_B_V12Vint0tF034_SFM.set_L(1024);
    // -0.340000  -2.492433008  1.070740576  0.997336337 -0.672072773  0.730735187  0.274248170  0.003964652  0.029720826 -0.000008785 -0.000001172    -5.070960888849387      0.669216041958857  0.839001188  0.836288740  0.374982544  0.391858646
    Var initV_B_V12Vint0tF034_SFM(N_VAR);
    initV_B_V12Vint0tF034_SFM.set_lnF(-2.492433008);
    initV_B_V12Vint0tF034_SFM.set_lmF(1.070740576);
    initV_B_V12Vint0tF034_SFM.set_nF(0.997336337);
    initV_B_V12Vint0tF034_SFM.set_mu(-0.672072773);
    initV_B_V12Vint0tF034_SFM.set_mF(0.730735187);
    initV_B_V12Vint0tF034_SFM.set_dF(0.274248170);
    initV_B_V12Vint0tF034_SFM.set_chiup(0.003964652);
    initV_B_V12Vint0tF034_SFM.set_chidown(0.029720826);
    initV_B_V12Vint0tF034_SFM.set_lchiup(-0.000008785);
    initV_B_V12Vint0tF034_SFM.set_lchidown(-0.000001172);

    // (B4-0-0-036-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.36, t'=0.00
    Par initPar_B_V12Vint0tF036_SFM(N_PAR);
    initPar_B_V12Vint0tF036_SFM.set_n(1.8);
    initPar_B_V12Vint0tF036_SFM.set_t(-1.);
    initPar_B_V12Vint0tF036_SFM.set_tPrim(0.00);
    initPar_B_V12Vint0tF036_SFM.set_U(5.);
    initPar_B_V12Vint0tF036_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF036_SFM.set_h(0.0);
    initPar_B_V12Vint0tF036_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF036_SFM.set_tF(-0.36);
    initPar_B_V12Vint0tF036_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF036_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF036_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF036_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF036_SFM.set_L(512);
    //    -0.360000  -2.426961403  0.704857238  0.988520751 -0.628798879  0.584730257  0.294255557  0.049831552  0.036330472  0.000016907  0.000023191    -5.074110477232410      0.538834619498553  0.780446251  0.771300405  0.165408821  0.213283582
    Var initV_B_V12Vint0tF036_SFM(N_VAR);
    initV_B_V12Vint0tF036_SFM.set_lnF(-2.426961403);
    initV_B_V12Vint0tF036_SFM.set_lmF(0.704857238);
    initV_B_V12Vint0tF036_SFM.set_nF(0.988520751);
    initV_B_V12Vint0tF036_SFM.set_mu(-0.628798879);
    initV_B_V12Vint0tF036_SFM.set_mF(0.584730257);
    initV_B_V12Vint0tF036_SFM.set_dF(0.294255557);
    initV_B_V12Vint0tF036_SFM.set_chiup(0.049831552);
    initV_B_V12Vint0tF036_SFM.set_chidown(0.036330472);
    initV_B_V12Vint0tF036_SFM.set_lchiup(0.000016907);
    initV_B_V12Vint0tF036_SFM.set_lchidown(0.000023191);

    // (B4-0-0-027-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.27, t'=0.25
    Par initPar_B_V12Vint0tF027_SFM(N_PAR);
    initPar_B_V12Vint0tF027_SFM.set_n(1.8);
    initPar_B_V12Vint0tF027_SFM.set_t(-1.);
    initPar_B_V12Vint0tF027_SFM.set_tPrim(0.25);
    initPar_B_V12Vint0tF027_SFM.set_U(5.);
    initPar_B_V12Vint0tF027_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF027_SFM.set_h(0.0);
    initPar_B_V12Vint0tF027_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF027_SFM.set_tF(-0.27);
    initPar_B_V12Vint0tF027_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF027_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF027_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF027_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF027_SFM.set_L(512);
    //-0.270000  -2.296879648  0.836043987  0.973405221 -0.860157161  0.649435765  0.270230681 -0.011370583  0.035299156 -0.000121510  0.000039141    -5.033185038727767      0.564669174834800  0.808893658  0.784578243  0.197707206  0.334297632
    Var initV_B_V12Vint0tF027_SFM(N_VAR);
    initV_B_V12Vint0tF027_SFM.set_lnF(-2.296879648);
    initV_B_V12Vint0tF027_SFM.set_lmF(0.836043987);
    initV_B_V12Vint0tF027_SFM.set_nF(0.973405221);
    initV_B_V12Vint0tF027_SFM.set_mu(-0.860157161);
    initV_B_V12Vint0tF027_SFM.set_mF(0.649435765);
    initV_B_V12Vint0tF027_SFM.set_dF(0.270230681);
    initV_B_V12Vint0tF027_SFM.set_chiup(-0.011370583);
    initV_B_V12Vint0tF027_SFM.set_chidown(0.035299156);
    initV_B_V12Vint0tF027_SFM.set_lchiup(-0.000121510);
    initV_B_V12Vint0tF027_SFM.set_lchidown(0.000039141);



    // (B2-001-0-02-PM) V=-1.2, h=0.01, Vint=0, tF=-1.0, t'=0.25
    Par initPar_Bh_V12Vint0tF10_PM(N_PAR);
    initPar_Bh_V12Vint0tF10_PM.set_n(1.8);
    initPar_Bh_V12Vint0tF10_PM.set_t(-1.);
    initPar_Bh_V12Vint0tF10_PM.set_tPrim(0.25);
    initPar_Bh_V12Vint0tF10_PM.set_U(5.);
    initPar_Bh_V12Vint0tF10_PM.set_V(-1.2);
    initPar_Bh_V12Vint0tF10_PM.set_h(0.1);
    initPar_Bh_V12Vint0tF10_PM.set_epsilonF(-3.0);
    initPar_Bh_V12Vint0tF10_PM.set_tF(-1.0);
    initPar_Bh_V12Vint0tF10_PM.set_gFg(1.);
    initPar_Bh_V12Vint0tF10_PM.set_Vint(-0.0);
    initPar_Bh_V12Vint0tF10_PM.set_alpha(0.0);
    initPar_Bh_V12Vint0tF10_PM.set_beta(5000.);
    initPar_Bh_V12Vint0tF10_PM.set_L(512);
    //    -1.000000  -2.300566420  0.084871374  0.953227112 -0.780971948  0.058877743  0.383733417  0.172028331  0.169738343  0.000003503  0.000003550    -5.698077386570055      0.084453964702879  0.898840381  0.897713476  0.000214167  0.004720089
    Var initV_Bh_V12Vint0tF10_PM(N_VAR);
    initV_Bh_V12Vint0tF10_PM.set_lnF(-2.300566420);
    initV_Bh_V12Vint0tF10_PM.set_lmF(0.084871374);
    initV_Bh_V12Vint0tF10_PM.set_nF(0.953227112);
    initV_Bh_V12Vint0tF10_PM.set_mu(-0.780971948);
    initV_Bh_V12Vint0tF10_PM.set_mF(0.058877743);
    initV_Bh_V12Vint0tF10_PM.set_dF(0.383733417);
    initV_Bh_V12Vint0tF10_PM.set_chiup(0.172028331);
    initV_Bh_V12Vint0tF10_PM.set_chidown(0.169738343);
    initV_Bh_V12Vint0tF10_PM.set_lchiup(0.000003503);
    initV_Bh_V12Vint0tF10_PM.set_lchidown(0.000003503);

    // (B3-001-0-0-PM) V=-1.2, h=0.01, Vint=0, tF=0, t'=0.25
    Par initPar_Bh_V30Vint0tF0_PM(N_PAR);
    initPar_Bh_V30Vint0tF0_PM.set_n(1.8);
    initPar_Bh_V30Vint0tF0_PM.set_t(-1.);
    initPar_Bh_V30Vint0tF0_PM.set_tPrim(0.25);
    initPar_Bh_V30Vint0tF0_PM.set_U(5.);
    initPar_Bh_V30Vint0tF0_PM.set_V(-3.0);
    initPar_Bh_V30Vint0tF0_PM.set_h(0.01);
    initPar_Bh_V30Vint0tF0_PM.set_epsilonF(-3.0);
    initPar_Bh_V30Vint0tF0_PM.set_tF(-0.0);
    initPar_Bh_V30Vint0tF0_PM.set_gFg(1.);
    initPar_Bh_V30Vint0tF0_PM.set_Vint(-0.0);
    initPar_Bh_V30Vint0tF0_PM.set_alpha(0.0);
    initPar_Bh_V30Vint0tF0_PM.set_beta(5000.);
    initPar_Bh_V30Vint0tF0_PM.set_L(512);
    //    -2.269544470  0.085499392  0.934779570 -2.264691812  0.049017108  0.401052681 -0.016860854  0.008096312 -0.000000000 -0.000000000    -7.835800634640634      0.047304694927307  0.947196389  0.946512226  0.004038298  0.000133447
    Var initV_Bh_V30Vint0tF0_PM(N_VAR);
    initV_Bh_V30Vint0tF0_PM.set_lnF(-2.269544470);
    initV_Bh_V30Vint0tF0_PM.set_lmF(0.085499392);
    initV_Bh_V30Vint0tF0_PM.set_nF(0.934779570);
    initV_Bh_V30Vint0tF0_PM.set_mu(-2.264691812);
    initV_Bh_V30Vint0tF0_PM.set_mF(0.049017108);
    initV_Bh_V30Vint0tF0_PM.set_dF(0.401052681);
    initV_Bh_V30Vint0tF0_PM.set_chiup(-0.016860854);
    initV_Bh_V30Vint0tF0_PM.set_chidown(0.008096312);
    initV_Bh_V30Vint0tF0_PM.set_lchiup(1e-12);
    initV_Bh_V30Vint0tF0_PM.set_lchidown(1e-12);


    //////////////////////////////////////////////////////////////
    // (C) badamy wplyw h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////

    // (B1-03-0-04-PM) V=-1.2, h=0.3, Vint=0, tF=-0.4, t'=0.00
    Par initPar_Ch_V12Vint0tF04_SFM(N_PAR);
    initPar_Ch_V12Vint0tF04_SFM.set_n(1.8);
    initPar_Ch_V12Vint0tF04_SFM.set_t(-1.);
    initPar_Ch_V12Vint0tF04_SFM.set_tPrim(0.00);
    initPar_Ch_V12Vint0tF04_SFM.set_U(5.);
    initPar_Ch_V12Vint0tF04_SFM.set_V(-1.2);
    initPar_Ch_V12Vint0tF04_SFM.set_h(0.3);
    initPar_Ch_V12Vint0tF04_SFM.set_epsilonF(-3.0);
    initPar_Ch_V12Vint0tF04_SFM.set_tF(-0.4);
    initPar_Ch_V12Vint0tF04_SFM.set_gFg(1.);
    initPar_Ch_V12Vint0tF04_SFM.set_Vint(-0.0);
    initPar_Ch_V12Vint0tF04_SFM.set_alpha(0.0);
    initPar_Ch_V12Vint0tF04_SFM.set_beta(5000.);
    initPar_Ch_V12Vint0tF04_SFM.set_L(512);
    //        -2.485902454  1.461854139  0.996375820 -0.531818206  0.825687590  0.243169824  0.013608250  0.027918488 -0.000008283 -0.000004037    -5.308283506560286      0.856087825218376  0.903331259  0.899625474  0.536424891  0.562340863
    Var initV_Ch_V12Vint0tF04_SFM(N_VAR);
    initV_Ch_V12Vint0tF04_SFM.set_lnF(-2.485902454);
    initV_Ch_V12Vint0tF04_SFM.set_lmF(1.461854139);
    initV_Ch_V12Vint0tF04_SFM.set_nF(0.996375820);
    initV_Ch_V12Vint0tF04_SFM.set_mu(-0.531818206);
    initV_Ch_V12Vint0tF04_SFM.set_mF(0.825687590);
    initV_Ch_V12Vint0tF04_SFM.set_dF(0.243169824);
    initV_Ch_V12Vint0tF04_SFM.set_chiup(0.013608250);
    initV_Ch_V12Vint0tF04_SFM.set_chidown(0.027918488);
    initV_Ch_V12Vint0tF04_SFM.set_lchiup(-0.000008283);
    initV_Ch_V12Vint0tF04_SFM.set_lchidown(-0.000004037);

    // (B1-03-0-04-PM) V=-1.2, h=0.1, Vint=0, tF=-0.5, t'=0.00
    Par initPar_Ch_V12Vint0tF05_PM(N_PAR);
    initPar_Ch_V12Vint0tF05_PM.set_n(1.8);
    initPar_Ch_V12Vint0tF05_PM.set_t(-1.);
    initPar_Ch_V12Vint0tF05_PM.set_tPrim(0.00);
    initPar_Ch_V12Vint0tF05_PM.set_U(5.);
    initPar_Ch_V12Vint0tF05_PM.set_V(-1.2);
    initPar_Ch_V12Vint0tF05_PM.set_h(0.02);
    initPar_Ch_V12Vint0tF05_PM.set_epsilonF(-3.0);
    initPar_Ch_V12Vint0tF05_PM.set_tF(-0.5);
    initPar_Ch_V12Vint0tF05_PM.set_gFg(1.);
    initPar_Ch_V12Vint0tF05_PM.set_Vint(-0.0);
    initPar_Ch_V12Vint0tF05_PM.set_alpha(0.0);
    initPar_Ch_V12Vint0tF05_PM.set_beta(5000.);
    initPar_Ch_V12Vint0tF05_PM.set_L(512);
    //-0.500000  -2.443047748  0.049348347  0.989889442 -0.639169144  0.046688420  0.351420458  0.138068412  0.137176712  0.000000218  0.000000220    -5.188587404735737      0.048060537590369  0.764922113  0.764476806  0.000100272  0.001883697
    Var initV_Ch_V12Vint0tF05_PM(N_VAR);
    initV_Ch_V12Vint0tF05_PM.set_lnF(-2.443047748);
    initV_Ch_V12Vint0tF05_PM.set_lmF(0.049348347);
    initV_Ch_V12Vint0tF05_PM.set_nF(0.989889442);
    initV_Ch_V12Vint0tF05_PM.set_mu(-0.639169144);
    initV_Ch_V12Vint0tF05_PM.set_mF(0.046688420);
    initV_Ch_V12Vint0tF05_PM.set_dF(0.351420458);
    initV_Ch_V12Vint0tF05_PM.set_chiup(0.138068412);
    initV_Ch_V12Vint0tF05_PM.set_chidown(0.137176712);
    initV_Ch_V12Vint0tF05_PM.set_lchiup(0.000000218);
    initV_Ch_V12Vint0tF05_PM.set_lchidown(0.000000220);

    //////////////////////////////////////////////////////////////
    // (D) badamy wplyw Vint na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////

    // (D1-0-10-08-SFM) V=-1.2, h=0.0, Vint=-1.0, tF=-0.8, t'=0.00
    Par initPar_D_V12Vint10tF08_SFM(N_PAR);
    initPar_D_V12Vint10tF08_SFM.set_n(1.8);
    initPar_D_V12Vint10tF08_SFM.set_t(-1.);
    initPar_D_V12Vint10tF08_SFM.set_tPrim(0.00);
    initPar_D_V12Vint10tF08_SFM.set_U(5.);
    initPar_D_V12Vint10tF08_SFM.set_V(-1.2);
    initPar_D_V12Vint10tF08_SFM.set_h(0.0);
    initPar_D_V12Vint10tF08_SFM.set_epsilonF(-3.0);
    initPar_D_V12Vint10tF08_SFM.set_tF(-0.8);
    initPar_D_V12Vint10tF08_SFM.set_gFg(1.);
    initPar_D_V12Vint10tF08_SFM.set_Vint(-1.0);
    initPar_D_V12Vint10tF08_SFM.set_alpha(0.0);
    initPar_D_V12Vint10tF08_SFM.set_beta(5000.);
    initPar_D_V12Vint10tF08_SFM.set_L(512);
    //         -2.627973719  0.814491086  1.036623177  0.694884270  0.479797947  0.403804529 -0.048345715  0.079411669  0.000485234 -0.000295410    -6.082172948136990      0.445893413694023  0.923487889  0.930180055  0.068978219  0.039085780
    Var initV_D_V12Vint10tF08_SFM(N_VAR);
    initV_D_V12Vint10tF08_SFM.set_lnF(-2.627973719);
    initV_D_V12Vint10tF08_SFM.set_lmF(0.814491086);
    initV_D_V12Vint10tF08_SFM.set_nF(1.036623177);
    initV_D_V12Vint10tF08_SFM.set_mu(0.694884270);
    initV_D_V12Vint10tF08_SFM.set_mF(0.479797947);
    initV_D_V12Vint10tF08_SFM.set_dF(0.403804529);
    initV_D_V12Vint10tF08_SFM.set_chiup(-0.048345715);
    initV_D_V12Vint10tF08_SFM.set_chidown(0.079411669);
    initV_D_V12Vint10tF08_SFM.set_lchiup(0.000485234);
    initV_D_V12Vint10tF08_SFM.set_lchidown(-0.000295410);

    // (D1-0-10-08-PM) V=-1.2, h=0.0, Vint=-1.0, tF=-0.8, t'=0.00
    Par initPar_D_V12Vint10tF08_PM(N_PAR);
    initPar_D_V12Vint10tF08_PM.set_n(1.8);
    initPar_D_V12Vint10tF08_PM.set_t(-1.);
    initPar_D_V12Vint10tF08_PM.set_tPrim(0.00);
    initPar_D_V12Vint10tF08_PM.set_U(5.);
    initPar_D_V12Vint10tF08_PM.set_V(-1.2);
    initPar_D_V12Vint10tF08_PM.set_h(0.0);
    initPar_D_V12Vint10tF08_PM.set_epsilonF(-3.0);
    initPar_D_V12Vint10tF08_PM.set_tF(-0.8);
    initPar_D_V12Vint10tF08_PM.set_gFg(1.);
    initPar_D_V12Vint10tF08_PM.set_Vint(-1.0);
    initPar_D_V12Vint10tF08_PM.set_alpha(0.0);
    initPar_D_V12Vint10tF08_PM.set_beta(5000.);
    initPar_D_V12Vint10tF08_PM.set_L(512);
    //  -2.734966309  0.000000000  1.056336738  0.694326318  0.000000000  0.442509893 -0.013088419 -0.013088419  0.000000000  0.000000000    -6.035404393691601      0.000000000000198  0.887967989  0.887967989  0.002857920  0.002857920
    Var initV_D_V12Vint10tF08_PM(N_VAR);
    initV_D_V12Vint10tF08_PM.set_lnF(-2.73496);
    initV_D_V12Vint10tF08_PM.set_lmF(1e-12);
    initV_D_V12Vint10tF08_PM.set_nF(1.05633);
    initV_D_V12Vint10tF08_PM.set_mu(0.69432);
    initV_D_V12Vint10tF08_PM.set_mF(1e-12);
    initV_D_V12Vint10tF08_PM.set_dF(0.44250);
    initV_D_V12Vint10tF08_PM.set_chiup(-0.0130);
    initV_D_V12Vint10tF08_PM.set_chidown(-0.0130);
    initV_D_V12Vint10tF08_PM.set_lchiup(1e-12);
    initV_D_V12Vint10tF08_PM.set_lchidown(1e-12);




	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_B_V12Vint0tF0_HM;
	Var initV(N_VAR); initV = initV_B_V12Vint0tF0_HM;

	printf("#dochodze do punktu startowego (Vtg)\n");

	//automatic_run_h(initPar, initV, 0.02, 0.00, 0.005); printf("\n");
	automatic_run_tPrim(initPar, initV, 0.25, 0.00, 0.05); printf("\n");
	//automatic_run_tF(initPar, initV, -0.00, -0.10, 0.001); printf("\n");

	//automatic_run_h(initPar, initV, 0.00, 0.03, 0.005); printf("\n");
	//automatic_run_gFg(initPar, initV, 1.00, 0.25, 0.01); printf("\n");
	//automatic_run_Vint(initPar, initV, -1.00, -0.8, 0.01); printf("\n");
	//automatic_run_tF(initPar, initV, -0.8, -0.5, 0.01); printf("\n");

	//automatic_run_n(initPar, initV, 1.6, 1.80, 0.01); printf("\n");
	//automatic_run_V(initPar, initV, -3.00, -1.2, 0.01); printf("\n");
	//automatic_run_tPrim(initPar, initV, 0.00, 0.25, 0.01); printf("\n");

	//automatic_run_U(initPar, initV, 20, 5.0, 1.0); printf("\n");
	//automatic_run_h(initPar, initV, 0., 0.1, 0.01); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -2.35, 0.05); printf("\n");
	//automatic_run_VtoP(initPar, initV, -1.75, -2.3, 0.01,  -12./5., -36./5.); printf("\n");
	//automatic_run_beta(initPar, initV, 500, 1, 5); printf("\n");
	//automatic_run_n(initPar, initV, 1.8, 1.5, 0.01); printf("\n");


	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;


    //automatic_run_tF(initPar, initV, -0.36, -0.32, 0.002); printf("\n");
    //automatic_run_tF(initPar, initV, -0.27, -0.40, 0.0005); printf("\n");

    automatic_run_Vint(initPar, initV, -0.00, 1.00, 0.005); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.2, -0.00, 0.005); printf("\n");

//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.6, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.4, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.2, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.1, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.0, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, 0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//    //
//
//    automatic_run_Vint(initPar, initV, -1.0, -4.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.6, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, -4.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.4, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, -4.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.2, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, -4.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_tF(initPar, initV, -0.8, -0.0, 0.01); printf("\n");
//    automatic_run_Vint(initPar, initV, -1.0, -4.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;

    //

//	automatic_run_h(initPar, initV, 0.01, 0.0, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.02, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.05, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.10, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.15, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.20, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.01, 0.30, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -1.0, -0.0, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;

	///
//
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.02, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.05, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.10, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.15, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.20, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;
//
//	automatic_run_h(initPar, initV, 0.0, 0.30, 0.01); printf("\n");
//	automatic_run_tF(initPar, initV, -0.1, -0.0, 0.002); printf("\n"); initPar=oldPar; initV=oldVar;

    printf("Koniec\n");
}


void run_2D() {

    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

    // (B2-0-0-0-HM) V=-1.2, h=0.0, Vint=0, tF=0, t'=0.25
    Par initPar_B_V12Vint0tF0_HM(N_PAR);
    initPar_B_V12Vint0tF0_HM.set_n(1.8);
    initPar_B_V12Vint0tF0_HM.set_t(-1.);
    initPar_B_V12Vint0tF0_HM.set_tPrim(0.25);
    initPar_B_V12Vint0tF0_HM.set_U(5.);
    initPar_B_V12Vint0tF0_HM.set_V(-1.2);
    initPar_B_V12Vint0tF0_HM.set_h(0.0);
    initPar_B_V12Vint0tF0_HM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF0_HM.set_tF(-0.0);
    initPar_B_V12Vint0tF0_HM.set_gFg(1.);
    initPar_B_V12Vint0tF0_HM.set_Vint(-0.0);
    initPar_B_V12Vint0tF0_HM.set_alpha(0.0);
    initPar_B_V12Vint0tF0_HM.set_beta(5000.);
    initPar_B_V12Vint0tF0_HM.set_L(512);
    //        -2.233439717  0.242535105  0.957803266 -0.877477471  0.257455342  0.294530643 -0.130743575 -0.005223736  0.000000000  0.000000000    -5.060748275674911      0.200000000000163  0.706205875  0.692179583  0.004533367  0.063157986
    Var initV_B_V12Vint0tF0_HM(N_VAR);
    initV_B_V12Vint0tF0_HM.set_lnF(-2.233439717);
    initV_B_V12Vint0tF0_HM.set_lmF(0.242535105);
    initV_B_V12Vint0tF0_HM.set_nF(0.957803266);
    initV_B_V12Vint0tF0_HM.set_mu(-0.877477471);
    initV_B_V12Vint0tF0_HM.set_mF(0.257455342);
    initV_B_V12Vint0tF0_HM.set_dF(0.294530643);
    initV_B_V12Vint0tF0_HM.set_chiup(-0.130743575);
    initV_B_V12Vint0tF0_HM.set_chidown(-0.005223736);
    initV_B_V12Vint0tF0_HM.set_lchiup(1e-12);
    initV_B_V12Vint0tF0_HM.set_lchidown(1e-12);

    // (B2-0-0-0-PM) V=-1.2, h=0.0, Vint=0, tF=0, t'=0.25
    Par initPar_B_V12Vint0tF0_PM(N_PAR);
    initPar_B_V12Vint0tF0_PM.set_n(1.8);
    initPar_B_V12Vint0tF0_PM.set_t(-1.);
    initPar_B_V12Vint0tF0_PM.set_tPrim(0.25);
    initPar_B_V12Vint0tF0_PM.set_U(5.);
    initPar_B_V12Vint0tF0_PM.set_V(-1.2);
    initPar_B_V12Vint0tF0_PM.set_h(0.0);
    initPar_B_V12Vint0tF0_PM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF0_PM.set_tF(-0.0);
    initPar_B_V12Vint0tF0_PM.set_gFg(1.);
    initPar_B_V12Vint0tF0_PM.set_Vint(-0.0);
    initPar_B_V12Vint0tF0_PM.set_alpha(0.0);
    initPar_B_V12Vint0tF0_PM.set_beta(5000.);
    initPar_B_V12Vint0tF0_PM.set_L(512);
    //        -2.219780009  0.000000000  0.956765407 -1.006625834  0.000000000  0.296026615 -0.054899591 -0.054899591  0.000000000  0.000000000    -5.046368791402772      0.000000000000010  0.677540789  0.677540789  0.008742181  0.008742181
    Var initV_B_V12Vint0tF0_PM(N_VAR);
    initV_B_V12Vint0tF0_PM.set_lnF(-2.219780009);
    initV_B_V12Vint0tF0_PM.set_lmF(1e-12);
    initV_B_V12Vint0tF0_PM.set_nF(0.956765407);
    initV_B_V12Vint0tF0_PM.set_mu(-1.006625834);
    initV_B_V12Vint0tF0_PM.set_mF(1e-12);
    initV_B_V12Vint0tF0_PM.set_dF(0.296026615);
    initV_B_V12Vint0tF0_PM.set_chiup(-0.054899591);
    initV_B_V12Vint0tF0_PM.set_chidown(-0.054899591);
    initV_B_V12Vint0tF0_PM.set_lchiup(1e-12);
    initV_B_V12Vint0tF0_PM.set_lchidown(1e-12);

    // (B2-0-0-01-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.1, t'=0.00
    Par initPar_B_V12Vint0tF01_SFM(N_PAR);
    initPar_B_V12Vint0tF01_SFM.set_n(1.8);
    initPar_B_V12Vint0tF01_SFM.set_t(-1.);
    initPar_B_V12Vint0tF01_SFM.set_tPrim(0.00);
    initPar_B_V12Vint0tF01_SFM.set_U(5.);
    initPar_B_V12Vint0tF01_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF01_SFM.set_h(0.0);
    initPar_B_V12Vint0tF01_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF01_SFM.set_tF(-0.1);
    initPar_B_V12Vint0tF01_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF01_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF01_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF01_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF01_SFM.set_L(512);
    //        -2.443121112  0.844733474  0.989944079 -0.662221836  0.670285765  0.273352951 -0.011967429  0.024615212 -0.000011369  0.000005528    -5.051508078101628      0.584540643064199  0.785405712  0.774634207  0.277265174  0.340393679
    Var initV_B_V12Vint0tF01_SFM(N_VAR);
    initV_B_V12Vint0tF01_SFM.set_lnF(-2.443121112);
    initV_B_V12Vint0tF01_SFM.set_lmF(0.844733474);
    initV_B_V12Vint0tF01_SFM.set_nF(0.989944079);
    initV_B_V12Vint0tF01_SFM.set_mu(-0.662221836);
    initV_B_V12Vint0tF01_SFM.set_mF(0.670285765);
    initV_B_V12Vint0tF01_SFM.set_dF(0.273352951);
    initV_B_V12Vint0tF01_SFM.set_chiup(-0.011967429);
    initV_B_V12Vint0tF01_SFM.set_chidown(0.024615212);
    initV_B_V12Vint0tF01_SFM.set_lchiup(-0.000011369);
    initV_B_V12Vint0tF01_SFM.set_lchidown(0.000005528);

    // (B2-0-0-02-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.2, t'=0.25
    Par initPar_B_V12Vint0tF02_SFM(N_PAR);
    initPar_B_V12Vint0tF02_SFM.set_n(1.8);
    initPar_B_V12Vint0tF02_SFM.set_t(-1.);
    initPar_B_V12Vint0tF02_SFM.set_tPrim(0.25);
    initPar_B_V12Vint0tF02_SFM.set_U(5.);
    initPar_B_V12Vint0tF02_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF02_SFM.set_h(0.0);
    initPar_B_V12Vint0tF02_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF02_SFM.set_tF(-0.2);
    initPar_B_V12Vint0tF02_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF02_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF02_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF02_SFM.set_beta(5000.);
    initPar_B_V12Vint0tF02_SFM.set_L(512);
    //-0.200000  -2.275891200  0.766044434  0.970139656 -0.840481120  0.624340668  0.269737199 -0.018190714  0.032730055 -0.000098520  0.000054755    -5.029044626085287      0.533009119632198  0.792954231  0.765962498  0.166442393  0.314224619
    Var initV_B_V12Vint0tF02_SFM(N_VAR);
    initV_B_V12Vint0tF02_SFM.set_lnF(-2.275891200);
    initV_B_V12Vint0tF02_SFM.set_lmF(0.766044434);
    initV_B_V12Vint0tF02_SFM.set_nF(0.970139656);
    initV_B_V12Vint0tF02_SFM.set_mu(-0.840481120);
    initV_B_V12Vint0tF02_SFM.set_mF(0.624340668);
    initV_B_V12Vint0tF02_SFM.set_dF(0.269737199);
    initV_B_V12Vint0tF02_SFM.set_chiup(-0.018190714);
    initV_B_V12Vint0tF02_SFM.set_chidown(0.032730055);
    initV_B_V12Vint0tF02_SFM.set_lchiup(-0.000098520);
    initV_B_V12Vint0tF02_SFM.set_lchidown(0.000054755);

    // (B3-0-0-034-SFM) V=-1.2, h=0.0, Vint=0, tF=-0.34, t'=0.00
    Par initPar_B_V12Vint0tF034_SFM(N_PAR);
    initPar_B_V12Vint0tF034_SFM.set_n(1.8);
    initPar_B_V12Vint0tF034_SFM.set_t(-1.);
    initPar_B_V12Vint0tF034_SFM.set_tPrim(0.00);
    initPar_B_V12Vint0tF034_SFM.set_U(5.);
    initPar_B_V12Vint0tF034_SFM.set_V(-1.2);
    initPar_B_V12Vint0tF034_SFM.set_h(0.0);
    initPar_B_V12Vint0tF034_SFM.set_epsilonF(-3.0);
    initPar_B_V12Vint0tF034_SFM.set_tF(-0.34);
    initPar_B_V12Vint0tF034_SFM.set_gFg(1.);
    initPar_B_V12Vint0tF034_SFM.set_Vint(-0.0);
    initPar_B_V12Vint0tF034_SFM.set_alpha(0.0);
    initPar_B_V12Vint0tF034_SFM.set_beta(25000.);
    initPar_B_V12Vint0tF034_SFM.set_L(1024);
    // -0.340000  -2.492433008  1.070740576  0.997336337 -0.672072773  0.730735187  0.274248170  0.003964652  0.029720826 -0.000008785 -0.000001172    -5.070960888849387      0.669216041958857  0.839001188  0.836288740  0.374982544  0.391858646
    Var initV_B_V12Vint0tF034_SFM(N_VAR);
    initV_B_V12Vint0tF034_SFM.set_lnF(-2.492433008);
    initV_B_V12Vint0tF034_SFM.set_lmF(1.070740576);
    initV_B_V12Vint0tF034_SFM.set_nF(0.997336337);
    initV_B_V12Vint0tF034_SFM.set_mu(-0.672072773);
    initV_B_V12Vint0tF034_SFM.set_mF(0.730735187);
    initV_B_V12Vint0tF034_SFM.set_dF(0.274248170);
    initV_B_V12Vint0tF034_SFM.set_chiup(0.003964652);
    initV_B_V12Vint0tF034_SFM.set_chidown(0.029720826);
    initV_B_V12Vint0tF034_SFM.set_lchiup(-0.000008785);
    initV_B_V12Vint0tF034_SFM.set_lchidown(-0.000001172);

    // (B2-001-0-02-PM) V=-1.2, h=0.01, Vint=0, tF=-1.0, t'=0.25
    Par initPar_Bh_V12Vint0tF10_PM(N_PAR);
    initPar_Bh_V12Vint0tF10_PM.set_n(1.8);
    initPar_Bh_V12Vint0tF10_PM.set_t(-1.);
    initPar_Bh_V12Vint0tF10_PM.set_tPrim(0.25);
    initPar_Bh_V12Vint0tF10_PM.set_U(5.);
    initPar_Bh_V12Vint0tF10_PM.set_V(-1.2);
    initPar_Bh_V12Vint0tF10_PM.set_h(0.1);
    initPar_Bh_V12Vint0tF10_PM.set_epsilonF(-3.0);
    initPar_Bh_V12Vint0tF10_PM.set_tF(-1.0);
    initPar_Bh_V12Vint0tF10_PM.set_gFg(1.);
    initPar_Bh_V12Vint0tF10_PM.set_Vint(-0.0);
    initPar_Bh_V12Vint0tF10_PM.set_alpha(0.0);
    initPar_Bh_V12Vint0tF10_PM.set_beta(5000.);
    initPar_Bh_V12Vint0tF10_PM.set_L(512);
    //    -1.000000  -2.300566420  0.084871374  0.953227112 -0.780971948  0.058877743  0.383733417  0.172028331  0.169738343  0.000003503  0.000003550    -5.698077386570055      0.084453964702879  0.898840381  0.897713476  0.000214167  0.004720089
    Var initV_Bh_V12Vint0tF10_PM(N_VAR);
    initV_Bh_V12Vint0tF10_PM.set_lnF(-2.300566420);
    initV_Bh_V12Vint0tF10_PM.set_lmF(0.084871374);
    initV_Bh_V12Vint0tF10_PM.set_nF(0.953227112);
    initV_Bh_V12Vint0tF10_PM.set_mu(-0.780971948);
    initV_Bh_V12Vint0tF10_PM.set_mF(0.058877743);
    initV_Bh_V12Vint0tF10_PM.set_dF(0.383733417);
    initV_Bh_V12Vint0tF10_PM.set_chiup(0.172028331);
    initV_Bh_V12Vint0tF10_PM.set_chidown(0.169738343);
    initV_Bh_V12Vint0tF10_PM.set_lchiup(0.000003503);
    initV_Bh_V12Vint0tF10_PM.set_lchidown(0.000003503);

    // (B3-001-0-0-PM) V=-1.2, h=0.01, Vint=0, tF=0, t'=0.25
    Par initPar_Bh_V30Vint0tF0_PM(N_PAR);
    initPar_Bh_V30Vint0tF0_PM.set_n(1.8);
    initPar_Bh_V30Vint0tF0_PM.set_t(-1.);
    initPar_Bh_V30Vint0tF0_PM.set_tPrim(0.25);
    initPar_Bh_V30Vint0tF0_PM.set_U(5.);
    initPar_Bh_V30Vint0tF0_PM.set_V(-3.0);
    initPar_Bh_V30Vint0tF0_PM.set_h(0.01);
    initPar_Bh_V30Vint0tF0_PM.set_epsilonF(-3.0);
    initPar_Bh_V30Vint0tF0_PM.set_tF(-0.0);
    initPar_Bh_V30Vint0tF0_PM.set_gFg(1.);
    initPar_Bh_V30Vint0tF0_PM.set_Vint(-0.0);
    initPar_Bh_V30Vint0tF0_PM.set_alpha(0.0);
    initPar_Bh_V30Vint0tF0_PM.set_beta(5000.);
    initPar_Bh_V30Vint0tF0_PM.set_L(512);
    //    -2.269544470  0.085499392  0.934779570 -2.264691812  0.049017108  0.401052681 -0.016860854  0.008096312 -0.000000000 -0.000000000    -7.835800634640634      0.047304694927307  0.947196389  0.946512226  0.004038298  0.000133447
    Var initV_Bh_V30Vint0tF0_PM(N_VAR);
    initV_Bh_V30Vint0tF0_PM.set_lnF(-2.269544470);
    initV_Bh_V30Vint0tF0_PM.set_lmF(0.085499392);
    initV_Bh_V30Vint0tF0_PM.set_nF(0.934779570);
    initV_Bh_V30Vint0tF0_PM.set_mu(-2.264691812);
    initV_Bh_V30Vint0tF0_PM.set_mF(0.049017108);
    initV_Bh_V30Vint0tF0_PM.set_dF(0.401052681);
    initV_Bh_V30Vint0tF0_PM.set_chiup(-0.016860854);
    initV_Bh_V30Vint0tF0_PM.set_chidown(0.008096312);
    initV_Bh_V30Vint0tF0_PM.set_lchiup(1e-12);
    initV_Bh_V30Vint0tF0_PM.set_lchidown(1e-12);

    // (Ch-002-0-05-PM) V=-1.2, h=0.02, Vint=0, tF=-0.5, t'=0.00
    Par initPar_Ch_V12Vint0tF05_PM(N_PAR);
    initPar_Ch_V12Vint0tF05_PM.set_n(1.8);
    initPar_Ch_V12Vint0tF05_PM.set_t(-1.);
    initPar_Ch_V12Vint0tF05_PM.set_tPrim(0.00);
    initPar_Ch_V12Vint0tF05_PM.set_U(5.);
    initPar_Ch_V12Vint0tF05_PM.set_V(-1.2);
    initPar_Ch_V12Vint0tF05_PM.set_h(0.02);
    initPar_Ch_V12Vint0tF05_PM.set_epsilonF(-3.0);
    initPar_Ch_V12Vint0tF05_PM.set_tF(-0.5);
    initPar_Ch_V12Vint0tF05_PM.set_gFg(1.);
    initPar_Ch_V12Vint0tF05_PM.set_Vint(-0.0);
    initPar_Ch_V12Vint0tF05_PM.set_alpha(0.0);
    initPar_Ch_V12Vint0tF05_PM.set_beta(5000.);
    initPar_Ch_V12Vint0tF05_PM.set_L(512);
    //-0.500000  -2.443047748  0.049348347  0.989889442 -0.639169144  0.046688420  0.351420458  0.138068412  0.137176712  0.000000218  0.000000220    -5.188587404735737      0.048060537590369  0.764922113  0.764476806  0.000100272  0.001883697
    Var initV_Ch_V12Vint0tF05_PM(N_VAR);
    initV_Ch_V12Vint0tF05_PM.set_lnF(-2.443047748);
    initV_Ch_V12Vint0tF05_PM.set_lmF(0.049348347);
    initV_Ch_V12Vint0tF05_PM.set_nF(0.989889442);
    initV_Ch_V12Vint0tF05_PM.set_mu(-0.639169144);
    initV_Ch_V12Vint0tF05_PM.set_mF(0.046688420);
    initV_Ch_V12Vint0tF05_PM.set_dF(0.351420458);
    initV_Ch_V12Vint0tF05_PM.set_chiup(0.138068412);
    initV_Ch_V12Vint0tF05_PM.set_chidown(0.137176712);
    initV_Ch_V12Vint0tF05_PM.set_lchiup(0.000000218);
    initV_Ch_V12Vint0tF05_PM.set_lchidown(0.000000220);

    /////////////////////////////////////////
    // D - dodatkowe punkty //
    /////////////////////////////////////////
    // (D1) V=-0, h=0.00, Vint=-0.5, tF=-0.5, t'=0.00
    Par initPar_D1_V05Vint05tF05_SFM(N_PAR);
    initPar_D1_V05Vint05tF05_SFM.set_n(1.4);
    initPar_D1_V05Vint05tF05_SFM.set_t(-1.);
    initPar_D1_V05Vint05tF05_SFM.set_tPrim(0.00);
    initPar_D1_V05Vint05tF05_SFM.set_U(5.);
    initPar_D1_V05Vint05tF05_SFM.set_V(-0.00);
    initPar_D1_V05Vint05tF05_SFM.set_h(0.00);
    initPar_D1_V05Vint05tF05_SFM.set_epsilonF(-3.0);
    initPar_D1_V05Vint05tF05_SFM.set_tF(-0.5);
    initPar_D1_V05Vint05tF05_SFM.set_gFg(1.);
    initPar_D1_V05Vint05tF05_SFM.set_Vint(-0.5);
    initPar_D1_V05Vint05tF05_SFM.set_alpha(0.0);
    initPar_D1_V05Vint05tF05_SFM.set_beta(5000.);
    initPar_D1_V05Vint05tF05_SFM.set_L(512);
    // -0.500000 0.000000    -2.058952937  1.530920528  0.951412380 -1.492673199  0.858228487  0.172901260  0.059695176  0.030453635  0.000381535  0.000747884    -4.434792704007732      0.859363659215267  0.939086206  0.881904838  0.486423624  0.914868515
    Var initV_D1_V05Vint05tF05_SFM(N_VAR);
    initV_D1_V05Vint05tF05_SFM.set_lnF(-2.058952937);
    initV_D1_V05Vint05tF05_SFM.set_lmF(1.530920528);
    initV_D1_V05Vint05tF05_SFM.set_nF(0.951412380);
    initV_D1_V05Vint05tF05_SFM.set_mu(-1.492673199);
    initV_D1_V05Vint05tF05_SFM.set_mF(0.858228487);
    initV_D1_V05Vint05tF05_SFM.set_dF(0.172901260);
    initV_D1_V05Vint05tF05_SFM.set_chiup(0.059695176);
    initV_D1_V05Vint05tF05_SFM.set_chidown(0.030453635);
    initV_D1_V05Vint05tF05_SFM.set_lchiup(0.000381535);
    initV_D1_V05Vint05tF05_SFM.set_lchidown(0.000747884);

    // (D2) V=-0.5, h=0.00, Vint=-0.0, tF=-0.0, t'=0.00
    Par initPar_D2_V05Vint00tF00_SFM(N_PAR);
    initPar_D2_V05Vint00tF00_SFM.set_n(1.6);
    initPar_D2_V05Vint00tF00_SFM.set_t(-1.);
    initPar_D2_V05Vint00tF00_SFM.set_tPrim(0.00);
    initPar_D2_V05Vint00tF00_SFM.set_U(5.);
    initPar_D2_V05Vint00tF00_SFM.set_V(-0.50);
    initPar_D2_V05Vint00tF00_SFM.set_h(0.00);
    initPar_D2_V05Vint00tF00_SFM.set_epsilonF(-3.0);
    initPar_D2_V05Vint00tF00_SFM.set_tF(-0.0);
    initPar_D2_V05Vint00tF00_SFM.set_gFg(1.);
    initPar_D2_V05Vint00tF00_SFM.set_Vint(-0.0);
    initPar_D2_V05Vint00tF00_SFM.set_alpha(0.0);
    initPar_D2_V05Vint00tF00_SFM.set_beta(5000.);
    initPar_D2_V05Vint00tF00_SFM.set_L(512);
    //0.000000 -0.500000    -2.338624647  2.197865971  0.989531387 -1.039351199  0.978607704  0.068802953  0.000585363  0.002673043  0.000000000  0.000000000    -4.505025118181071      0.968636178035097  0.978829002  0.938900910  3.009230055  3.589680739
    Var initV_D2_V05Vint00tF00_SFM(N_VAR);
    initV_D2_V05Vint00tF00_SFM.set_lnF(-2.338624647);
    initV_D2_V05Vint00tF00_SFM.set_lmF(2.197865971);
    initV_D2_V05Vint00tF00_SFM.set_nF(0.989531387);
    initV_D2_V05Vint00tF00_SFM.set_mu(-1.039351199);
    initV_D2_V05Vint00tF00_SFM.set_mF(0.978607704);
    initV_D2_V05Vint00tF00_SFM.set_dF(0.068802953);
    initV_D2_V05Vint00tF00_SFM.set_chiup(0.000585363);
    initV_D2_V05Vint00tF00_SFM.set_chidown(0.002673043);
    initV_D2_V05Vint00tF00_SFM.set_lchiup(1e-7);
    initV_D2_V05Vint00tF00_SFM.set_lchidown(1e-7);

    // (D1) V=-0, h=0.00, Vint=-0.5, tF=-0.1, t'=0.00
    Par initPar_D3_V00Vint05tF01_SFM(N_PAR);
    initPar_D3_V00Vint05tF01_SFM.set_n(1.6);
    initPar_D3_V00Vint05tF01_SFM.set_t(-1.);
    initPar_D3_V00Vint05tF01_SFM.set_tPrim(0.00);
    initPar_D3_V00Vint05tF01_SFM.set_U(5.);
    initPar_D3_V00Vint05tF01_SFM.set_V(-0.00);
    initPar_D3_V00Vint05tF01_SFM.set_h(0.00);
    initPar_D3_V00Vint05tF01_SFM.set_epsilonF(-3.0);
    initPar_D3_V00Vint05tF01_SFM.set_tF(-0.1);
    initPar_D3_V00Vint05tF01_SFM.set_gFg(1.);
    initPar_D3_V00Vint05tF01_SFM.set_Vint(-0.5);
    initPar_D3_V00Vint05tF01_SFM.set_alpha(0.0);
    initPar_D3_V00Vint05tF01_SFM.set_beta(5000.);
    initPar_D3_V00Vint05tF01_SFM.set_L(512);
    //-0.500000 0.000000    -2.505870390  2.223699715  1.000845397 -1.005899703  0.957668569  0.141517463  0.008917547  0.013897224  0.000000075  0.000000048    -4.633963925595189      0.962118927519319  0.982043121  0.982731400  0.713344658  0.707892520
    Var initV_D3_V00Vint05tF01_SFM(N_VAR);
    initV_D3_V00Vint05tF01_SFM.set_lnF(-2.505870390);
    initV_D3_V00Vint05tF01_SFM.set_lmF(2.223699715);
    initV_D3_V00Vint05tF01_SFM.set_nF(1.000845397);
    initV_D3_V00Vint05tF01_SFM.set_mu(-1.005899703);
    initV_D3_V00Vint05tF01_SFM.set_mF(0.957668569);
    initV_D3_V00Vint05tF01_SFM.set_dF(0.141517463);
    initV_D3_V00Vint05tF01_SFM.set_chiup(0.008917547);
    initV_D3_V00Vint05tF01_SFM.set_chidown(0.013897224);
    initV_D3_V00Vint05tF01_SFM.set_lchiup(0.000000075);
    initV_D3_V00Vint05tF01_SFM.set_lchidown(0.000000048);

    // (D1) V=-0, h=0.00, Vint=-0.5, tF=-0.1, t'=0.00
    Par initPar_D4_V00Vint05tF05_SFM(N_PAR);
    initPar_D4_V00Vint05tF05_SFM.set_n(1.8);
    initPar_D4_V00Vint05tF05_SFM.set_t(-1.);
    initPar_D4_V00Vint05tF05_SFM.set_tPrim(0.00);
    initPar_D4_V00Vint05tF05_SFM.set_U(5.);
    initPar_D4_V00Vint05tF05_SFM.set_V(-0.00);
    initPar_D4_V00Vint05tF05_SFM.set_h(0.00);
    initPar_D4_V00Vint05tF05_SFM.set_epsilonF(-3.0);
    initPar_D4_V00Vint05tF05_SFM.set_tF(-0.5);
    initPar_D4_V00Vint05tF05_SFM.set_gFg(1.);
    initPar_D4_V00Vint05tF05_SFM.set_Vint(-0.5);
    initPar_D4_V00Vint05tF05_SFM.set_alpha(0.0);
    initPar_D4_V00Vint05tF05_SFM.set_beta(5000.);
    initPar_D4_V00Vint05tF05_SFM.set_L(512);
    //-0.500000 0.000000    -2.568314282  2.176284642  1.010738636 -0.428389731  0.942069120  0.178908057  0.015094823  0.021507699  0.000005499  0.000003860    -4.842718780908253      0.999774282987322  0.981251926  0.986972347  0.474651033  0.434780303
    Var initV_D4_V00Vint05tF05_SFM(N_VAR);
    initV_D4_V00Vint05tF05_SFM.set_lnF(-2.568314282);
    initV_D4_V00Vint05tF05_SFM.set_lmF(2.176284642);
    initV_D4_V00Vint05tF05_SFM.set_nF(1.010738636);
    initV_D4_V00Vint05tF05_SFM.set_mu(-0.428389731);
    initV_D4_V00Vint05tF05_SFM.set_mF(0.942069120);
    initV_D4_V00Vint05tF05_SFM.set_dF(0.178908057);
    initV_D4_V00Vint05tF05_SFM.set_chiup(0.015094823);
    initV_D4_V00Vint05tF05_SFM.set_chidown(0.021507699);
    initV_D4_V00Vint05tF05_SFM.set_lchiup(0.000005499);
    initV_D4_V00Vint05tF05_SFM.set_lchidown(0.000003860);


	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_D4_V00Vint05tF05_SFM;
	Var initV(N_VAR); initV = initV_D4_V00Vint05tF05_SFM;

	printf("#dochodze do punktu startowego (Vtg)\n");

	//automatic_run_h(initPar, initV, 0.02, 0.00, 0.005); printf("\n");
	automatic_run_tPrim(initPar, initV, 0.00, 0.25, 0.01); printf("\n");
	//automatic_run_tF(initPar, initV, -0.50, -0.20, 0.01); printf("\n");

	//automatic_run_V(initPar, initV, -1.2, -1.0, 0.01); printf("\n");
	//automatic_run_tPrim(initPar, initV, 0.00, 0.25, 0.01); printf("\n");
	//automatic_run_tPrim(initPar, initV, 0.25, 0.00, 0.01); printf("\n");
	//automatic_run_n(initPar, initV, 1.8, 1.40, 0.01); printf("\n");

	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

    automatic_2Drun_VintV(initPar, initV, -0.5, -0., 0.02, -0, -4.0, 0.02);  printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_2Drun_VintV(initPar, initV, -0.5, -4., 0.02, -0, -4.0, 0.02);

//    automatic_2Drun_VVint(initPar, initV, -0.5, -0.0, 0.02, 0.0, -4., 0.02);  printf("\n"); initPar=oldPar; initV=oldVar;
//    automatic_2Drun_VVint(initPar, initV, -0.5, -4.0, 0.02, 0.0, -4., 0.02);

	printf("Koniec\n");
}


void run_2D_VandVint() {

    // (1)
    Par initPar_HM(N_PAR);
    initPar_HM.set_n(1.6);
    initPar_HM.set_t(-1.);
    initPar_HM.set_tPrim(0.25);
    initPar_HM.set_U(5.);
    initPar_HM.set_V(-1.7);
    initPar_HM.set_h(0.05);
    initPar_HM.set_epsilonF(-3.0);
    initPar_HM.set_tF(-0.0);
    initPar_HM.set_gFg(1.);
    initPar_HM.set_Vint(-0.0);
    initPar_HM.set_alpha(0.0);
    initPar_HM.set_beta(5000.);
    initPar_HM.set_L(512);
    // -1.700000  -2.434985514  0.772409584  0.777520130 -0.984860591  0.496530872  0.076792158 -0.104899284  0.028902199  0.000000000 -0.000000000    -5.136999781975028      0.399999999999365  0.719306127  0.462525890  0.251566292  1.241905395
    Var initV_HM(N_VAR);
    initV_HM.set_lnF(-2.434985514);
    initV_HM.set_lmF(0.772409584);
    initV_HM.set_nF(0.777520130);
    initV_HM.set_mu(-0.984860591);
    initV_HM.set_mF(0.496530872);
    initV_HM.set_dF(0.076792158);
    initV_HM.set_chiup(-0.104899284);
    initV_HM.set_chidown(0.028902199);
    initV_HM.set_lchiup(1e-12);
    initV_HM.set_lchidown(1e-12);

    // (2a)
    Par initPar_PMa(N_PAR);
    initPar_PMa.set_n(1.6);
    initPar_PMa.set_t(-1.);
    initPar_PMa.set_tPrim(0.25);
    initPar_PMa.set_U(5.);
    initPar_PMa.set_V(-5.0);
    initPar_PMa.set_h(0.05);
    initPar_PMa.set_epsilonF(-3.0);
    initPar_PMa.set_tF(-0.0);
    initPar_PMa.set_gFg(1.);
    initPar_PMa.set_Vint(-0.0);
    initPar_PMa.set_alpha(0.0);
    initPar_PMa.set_beta(5000.);
    initPar_PMa.set_L(512);
    //-5.010000  -4.005021134  0.314914607  0.650077146 -3.179786792  0.076179928  0.179376660  0.027721380  0.047170077 -0.000000000 -0.000000000    -9.427318492730993      0.091399661631935  0.860686916  0.842536783  0.145098308  0.206854990
    Var initV_PMa(N_VAR);
    initV_PMa.set_lnF(-4.005021134);
    initV_PMa.set_lmF(0.314914607);
    initV_PMa.set_nF(0.650077146);
    initV_PMa.set_mu(-3.179786792);
    initV_PMa.set_mF(0.076179928);
    initV_PMa.set_dF(0.179376660);
    initV_PMa.set_chiup(0.027721380);
    initV_PMa.set_chidown(0.047170077);
    initV_PMa.set_lchiup(1e-12);
    initV_PMa.set_lchidown(1e-12);

    // (2b) -- w dół
    Par initPar_PMb(N_PAR);
    initPar_PMb.set_n(1.6);
    initPar_PMb.set_t(-1.);
    initPar_PMb.set_tPrim(0.25);
    initPar_PMb.set_U(20.);
    initPar_PMb.set_V(-0.0);
    initPar_PMb.set_h(0.05);
    initPar_PMb.set_epsilonF(-3.0);
    initPar_PMb.set_tF(-0.0);
    initPar_PMb.set_gFg(1.);
    initPar_PMb.set_Vint(-2.0);
    initPar_PMb.set_alpha(0.0);
    initPar_PMb.set_beta(5000.);
    initPar_PMb.set_L(512);
    //-2.060000 0.000000    -3.607891317  0.055960198  0.661922287 -0.920476991  0.017785718  0.157118408 -0.047570832 -0.045823007 -0.000000000  0.000000000    -7.425312352298523      0.045251197444834  0.800591287  0.795099696  0.241424856  0.259431788
    Var initV_PMb(N_VAR);
    initV_PMb.set_lnF(-3.607891317);
    initV_PMb.set_lmF(0.055960198);
    initV_PMb.set_nF(0.661922287);
    initV_PMb.set_mu(-0.920476991);
    initV_PMb.set_mF(0.017785718);
    initV_PMb.set_dF(0.157118408);
    initV_PMb.set_chiup(-0.047570832);
    initV_PMb.set_chidown(-0.045823007);
    initV_PMb.set_lchiup(1e-12);
    initV_PMb.set_lchidown(1e-12);

    // (2c) -- SFM/HM w górę
    Par initPar_PMc(N_PAR);
    initPar_PMc.set_n(1.6);
    initPar_PMc.set_t(-1.);
    initPar_PMc.set_tPrim(0.25);
    initPar_PMc.set_U(20.);
    initPar_PMc.set_V(-0.0);
    initPar_PMc.set_h(0.05);
    initPar_PMc.set_epsilonF(-3.0);
    initPar_PMc.set_tF(-0.0);
    initPar_PMc.set_gFg(1.);
    initPar_PMc.set_Vint(-1.0);
    initPar_PMc.set_alpha(0.0);
    initPar_PMc.set_beta(5000.);
    initPar_PMc.set_L(512);
    //-1.000000 0.000000    -3.019133923  2.108319197  0.837064182 -0.740785146  0.766216716  0.070894782 -0.065176091  0.022513294 -0.000000000  0.000000000    -5.083076322785486      0.680278414531159  0.899273712  0.531246337  0.005769882  2.315687609
    Var initV_PMc(N_VAR);
    initV_PMc.set_lnF(-3.019133923);
    initV_PMc.set_lmF(2.108319197);
    initV_PMc.set_nF(0.837064182);
    initV_PMc.set_mu(-0.740785146);
    initV_PMc.set_mF(0.766216716);
    initV_PMc.set_dF(0.070894782);
    initV_PMc.set_chiup(-0.065176091);
    initV_PMc.set_chidown(0.022513294);
    initV_PMc.set_lchiup(1e-12);
    initV_PMc.set_lchidown(1e-12);

    // (3)
    Par initPar_SFM(N_PAR);
    initPar_SFM.set_n(1.6);
    initPar_SFM.set_t(-1.);
    initPar_SFM.set_tPrim(0.25);
    initPar_SFM.set_U(20.);
    initPar_SFM.set_V(-0.0);
    initPar_SFM.set_h(0.05);
    initPar_SFM.set_epsilonF(-3.0);
    initPar_SFM.set_tF(-0.0);
    initPar_SFM.set_gFg(1.);
    initPar_SFM.set_Vint(-0.2);
    initPar_SFM.set_alpha(0.0);
    initPar_SFM.set_beta(5000.);
    initPar_SFM.set_L(512);
    //-0.200000 0.000000    -9.306244130  9.262350872  0.997253563 -1.308729418  0.996808765  0.014259761  0.001204526  0.000162960  0.000000000 -0.000000000    -4.335062570408685      1.017565992985448  0.995660117  0.942225402 17.205355615 19.344559363
    Var initV_SFM(N_VAR);
    initV_SFM.set_lnF(-9.306244130);
    initV_SFM.set_lmF(9.262350872);
    initV_SFM.set_nF(0.997253563);
    initV_SFM.set_mu(-1.308729418);
    initV_SFM.set_mF(0.996808765);
    initV_SFM.set_dF(0.014259761);
    initV_SFM.set_chiup(0.001204526);
    initV_SFM.set_chidown(0.000162960);
    initV_SFM.set_lchiup(1e-12);
    initV_SFM.set_lchidown(1e-12);

	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_PMa;
	Var initV(N_VAR); initV = initV_PMa;

	printf("#dochodze do punktu startowego (2D V and Vint -- dokladnie)\n");

	//(1) HM z dolu L i P
	//automatic_run_V(initPar, initV, -1.7, -1.8, 0.05); printf("\n"); //(b)
	//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	//automatic_run_U(initPar, initV, 5., 20.0, 1.); printf("\n");
	//automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");
	//automatic_run_h(initPar, initV, 0.05, 0.0, 0.005); printf("\n");

	//(2a) PM z prawej
	automatic_run_V(initPar, initV, -5.0, -10.0, 0.1); printf("\n"); //(b)
	automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	automatic_run_U(initPar, initV, 5., 20.0, 1.); printf("\n");
	automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");
	automatic_run_h(initPar, initV, 0.05, 0.000, 0.005); printf("\n");
	initV.shake(1e-5);

	//(2b) PM z gory
	//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	//automatic_run_U(initPar, initV, 20., 5.0, 1.); printf("\n");
	//automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");
	//automatic_run_h(initPar, initV, 0.05, 0.0, 0.005); printf("\n");

	//(2c) SFM/HM w gorę
	//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	//automatic_run_U(initPar, initV, 20., 5.0, 1.); printf("\n");
	//automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");
	//automatic_run_h(initPar, initV, 0.05, 0.0, 0.005); printf("\n");

	//(3) SFM z lewej
	//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	//automatic_run_U(initPar, initV, 20., 5.0, 0.5); printf("\n");
	//automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");
	//automatic_run_h(initPar, initV, 0.05, 0.0, 0.005); printf("\n");



	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

    //(1)
    //automatic_2Drun_VintV(initPar, initV, -0, -2., 0.01, -1.7, -0.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_VintV(initPar, initV, -0, -2., 0.01, -1.7, -4.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(1b)
    //automatic_2Drun_VintV(initPar, initV, -0, -2., 0.01, -1.8, -0.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_VintV(initPar, initV, -0, -2., 0.01, -1.8, -4.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(2a)
    automatic_2Drun_VintV(initPar, initV, -0, -2., 0.01, -10.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(2b)
    //automatic_2Drun_VVint(initPar, initV, -0.0, -0.-4, 0.01, -2.0, -1.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(2c)
    //automatic_2Drun_VVint(initPar, initV, -0.0, -0.-4, 0.01, -1.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(3)
    //automatic_2Drun_VintV(initPar, initV, -0.2, -0., 0.01, -0.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_VintV(initPar, initV, -0.2, -2., 0.01, -0.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

	return;
}


void run_2D_hVint() {

//    // (1) HM
//    Par initPar_HM(N_PAR);
//    initPar_HM.set_n(1.6);
//    initPar_HM.set_t(-1.);
//    initPar_HM.set_tPrim(0.25);
//    initPar_HM.set_U(20.);
//    initPar_HM.set_V(-1.5);
//    initPar_HM.set_h(0.01);
//    initPar_HM.set_epsilonF(-3.0);
//    initPar_HM.set_tF(-0.0);
//    initPar_HM.set_gFg(1.);
//    initPar_HM.set_Vint(-1.0);
//    initPar_HM.set_alpha(0.0);
//    initPar_HM.set_beta(5000.);
//    initPar_HM.set_L(512);
//    //-1.500000  -3.390796890  1.405619587  0.780760467 -0.308804614  0.553092542  0.114017122 -0.101478956  0.045025651  0.000000000 -0.000000000    -5.915225940467859      0.400000000000000  0.816605139  0.596151700  0.066682642  1.022709381
//    Var initV_HM(N_VAR);
//    initV_HM.set_lnF(-3.390796890);
//    initV_HM.set_lmF(1.405619587);
//    initV_HM.set_nF(0.780760467);
//    initV_HM.set_mu(-0.308804614);
//    initV_HM.set_mF(0.553092542);
//    initV_HM.set_dF(0.114017122);
//    initV_HM.set_chiup(-0.101478956);
//    initV_HM.set_chidown(0.045025651);
//    initV_HM.set_lchiup(1e-12);
//    initV_HM.set_lchidown(1e-12);
//
//    // (2) PM
//    Par initPar_PM(N_PAR);
//    initPar_PM.set_n(1.6);
//    initPar_PM.set_t(-1.);
//    initPar_PM.set_tPrim(0.25);
//    initPar_PM.set_U(20.);
//    initPar_PM.set_V(-0.0);
//    initPar_PM.set_h(0.01);
//    initPar_PM.set_epsilonF(-3.0);
//    initPar_PM.set_tF(-0.0);
//    initPar_PM.set_gFg(1.);
//    initPar_PM.set_Vint(-3.0);
//    initPar_PM.set_alpha(0.0);
//    initPar_PM.set_beta(5000.);
//    initPar_PM.set_L(512);
//    //-3.000000  -4.335728627  0.008447788  0.650931153 -1.067260531  0.001907373  0.197300036 -0.031853349 -0.031720816  0.000000000  0.000000000   -10.037279826793483      0.005969569901654  0.878209771  0.877839849  0.130706361  0.131993022
//    Var initV_PM(N_VAR);
//    initV_PM.set_lnF(-4.335728627);
//    initV_PM.set_lmF(0.008447788);
//    initV_PM.set_nF(0.650931153);
//    initV_PM.set_mu(-1.067260531);
//    initV_PM.set_mF(0.001907373);
//    initV_PM.set_dF(0.197300036);
//    initV_PM.set_chiup(-0.031853349);
//    initV_PM.set_chidown(-0.031853349);
//    initV_PM.set_lchiup(1e-12);
//    initV_PM.set_lchidown(1e-12);
//
//    // (3) SFM
//    Par initPar_SFM(N_PAR);
//    initPar_SFM.set_n(1.6);
//    initPar_SFM.set_t(-1.);
//    initPar_SFM.set_tPrim(0.25);
//    initPar_SFM.set_U(20.);
//    initPar_SFM.set_V(-0.0);
//    initPar_SFM.set_h(0.01);
//    initPar_SFM.set_epsilonF(-3.0);
//    initPar_SFM.set_tF(-0.0);
//    initPar_SFM.set_gFg(1.);
//    initPar_SFM.set_Vint(-1.0);
//    initPar_SFM.set_alpha(0.0);
//    initPar_SFM.set_beta(25000.);
//    initPar_SFM.set_L(512);
//    //0.010000  -3.000045029  2.085425682  0.835631244 -0.731573807  0.763697150  0.070916838 -0.065665196  0.022782464  0.000000000 -0.000000000    -5.056289304917529      0.658879710810171  0.898357567  0.530382128  0.007119315  2.298496526
//    Var initV_SFM(N_VAR);
//    initV_SFM.set_lnF(-3.000045029);
//    initV_SFM.set_lmF(2.085425682);
//    initV_SFM.set_nF(0.835631244);
//    initV_SFM.set_mu(-0.731573807);
//    initV_SFM.set_mF(0.763697150);
//    initV_SFM.set_dF(0.070916838);
//    initV_SFM.set_chiup(-0.065665196);
//    initV_SFM.set_chidown(0.022782464);
//    initV_SFM.set_lchiup(1e-8);
//    initV_SFM.set_lchidown(1e-8);
//
////#automatic_run_h, start 0.000000, stop 0.010000, step 0.005000 | PARAMETERS: n=1.600000, t=-1.000000, tPrim=0.250000, U=20.000000, V=-0.000000, h=0.000000, epsilonF=-3.000000, tF=-0.000000, gFg=1.000000, Vint=-1.000000, alpha=0.000000, beta=5000.000000, L=512
////#init_p    -2.995625732  2.080173848  0.835296983 -0.728613827  0.763112606  0.070920454 -0.065776219  0.022844746 -0.000000000 -0.000000000
////#h             lnF          lmF          nF             mu            mF           d       chiup        chidown      lchiup      lchidown             E                       m             qup           qdown       q2up           q2down
////0.000000  -2.995625732  2.080173848  0.835296983 -0.728613827  0.763112606  0.070920454 -0.065776219  0.022844746  0.000000000  0.000000000    -5.049724808395116      0.653797483702944  0.898150253  0.530189570  0.007449739  2.294540796
////0.005000  -2.998038983  2.083023312  0.835479946 -0.730161338  0.763430716  0.070918892 -0.065714507  0.022810854  0.000000000 -0.000000000    -5.053000291246465      0.656493027871781  0.898260902  0.530292045  0.007269070  2.296696293
////0.010000  -3.000045029  2.085425682  0.835631244 -0.731573807  0.763697150  0.070916838 -0.065665196  0.022782464  0.000000000 -0.000000000    -5.056289304917529      0.658879710810171  0.898357567  0.530382128  0.007119315  2.298496526
//
//	// I'm choosing start point
//
//	Par initPar(N_PAR); initPar = initPar_HM;
//	Var initV(N_VAR); initV = initV_HM;
//
//	printf("#dochodze do punktu startowego (run_2D_hVint)\n");
//
//	// HM
//	automatic_run_Vint(initPar, initV, -1.0, -1.5, 0.1); printf("\n");
//	automatic_run_V(initPar, initV, -1.5, -0.5, 0.1); printf("\n");
//	automatic_run_Vint(initPar, initV, -1.5, -1.4, 0.1); printf("\n");
//	automatic_run_V(initPar, initV, -0.5, -0.0, 0.1); printf("\n");
//	automatic_run_h(initPar, initV, 0.00, 0.01, 0.005); printf("\n");
//
//	//PM
////	automatic_run_n(initPar, initV, 1.8, 1.60, 0.01); printf("\n");
////	automatic_run_V(initPar, initV, -3.0, -6.0, 0.1); printf("\n");
////	automatic_run_Vint(initPar, initV, -0, -6.0, 0.1); printf("\n");
////	automatic_run_V(initPar, initV, -6.0, -0.0, 0.1); printf("\n");
////	automatic_run_U(initPar, initV, 5, 20.0, 1.); printf("\n");
////	automatic_run_Vint(initPar, initV, -6.0, -1.0, 0.1); printf("\n");
//
//
//
//	//automatic_run_tPrim(initPar, initV, 0.00, 0.25, 0.01); printf("\n");
//	//automatic_run_tF(initPar, initV, -0.50, -0.20, 0.01); printf("\n");
////	automatic_run_h(initPar, initV, 0.01, 0.00, 0.005); printf("\n");
////	automatic_run_Vint(initPar, initV, -1, -2.0, 0.02); printf("\n");
//
//
//	printf("#Jestem w punkcie startowym\n");
//    Par oldPar = initPar;
//    Var oldVar = initV;
//
//
//	printf("Koniec\n");

	return;
}

void run_2D_hV() {

    // (1)
    Par initPar_HM(N_PAR);
    initPar_HM.set_n(1.6);
    initPar_HM.set_t(-1.);
    initPar_HM.set_tPrim(0.25);
    initPar_HM.set_U(5.);
    initPar_HM.set_V(-1.7);
    initPar_HM.set_h(0.05);
    initPar_HM.set_epsilonF(-3.0);
    initPar_HM.set_tF(-0.0);
    initPar_HM.set_gFg(1.);
    initPar_HM.set_Vint(-0.0);
    initPar_HM.set_alpha(0.0);
    initPar_HM.set_beta(5000.);
    initPar_HM.set_L(512);
    // -1.700000  -2.434985514  0.772409584  0.777520130 -0.984860591  0.496530872  0.076792158 -0.104899284  0.028902199  0.000000000 -0.000000000    -5.136999781975028      0.399999999999365  0.719306127  0.462525890  0.251566292  1.241905395
    Var initV_HM(N_VAR);
    initV_HM.set_lnF(-2.434985514);
    initV_HM.set_lmF(0.772409584);
    initV_HM.set_nF(0.777520130);
    initV_HM.set_mu(-0.984860591);
    initV_HM.set_mF(0.496530872);
    initV_HM.set_dF(0.076792158);
    initV_HM.set_chiup(-0.104899284);
    initV_HM.set_chidown(0.028902199);
    initV_HM.set_lchiup(1e-12);
    initV_HM.set_lchidown(1e-12);

    // (2)
    Par initPar_PM(N_PAR);
    initPar_PM.set_n(1.6);
    initPar_PM.set_t(-1.);
    initPar_PM.set_tPrim(0.25);
    initPar_PM.set_U(5.);
    initPar_PM.set_V(-5.0);
    initPar_PM.set_h(0.05);
    initPar_PM.set_epsilonF(-3.0);
    initPar_PM.set_tF(-0.0);
    initPar_PM.set_gFg(1.);
    initPar_PM.set_Vint(-0.0);
    initPar_PM.set_alpha(0.0);
    initPar_PM.set_beta(5000.);
    initPar_PM.set_L(512);
    //-5.010000  -4.005021134  0.314914607  0.650077146 -3.179786792  0.076179928  0.179376660  0.027721380  0.047170077 -0.000000000 -0.000000000    -9.427318492730993      0.091399661631935  0.860686916  0.842536783  0.145098308  0.206854990
    Var initV_PM(N_VAR);
    initV_PM.set_lnF(-4.005021134);
    initV_PM.set_lmF(0.314914607);
    initV_PM.set_nF(0.650077146);
    initV_PM.set_mu(-3.179786792);
    initV_PM.set_mF(0.076179928);
    initV_PM.set_dF(0.179376660);
    initV_PM.set_chiup(0.027721380);
    initV_PM.set_chidown(0.047170077);
    initV_PM.set_lchiup(1e-12);
    initV_PM.set_lchidown(1e-12);

    // (3)
    Par initPar_SFM(N_PAR);
    initPar_SFM.set_n(1.6);
    initPar_SFM.set_t(-1.);
    initPar_SFM.set_tPrim(0.25);
    initPar_SFM.set_U(20.);
    initPar_SFM.set_V(-0.0);
    initPar_SFM.set_h(0.05);
    initPar_SFM.set_epsilonF(-3.0);
    initPar_SFM.set_tF(-0.0);
    initPar_SFM.set_gFg(1.);
    initPar_SFM.set_Vint(-0.2);
    initPar_SFM.set_alpha(0.0);
    initPar_SFM.set_beta(5000.);
    initPar_SFM.set_L(512);
    //-0.200000 0.000000    -9.306244130  9.262350872  0.997253563 -1.308729418  0.996808765  0.014259761  0.001204526  0.000162960  0.000000000 -0.000000000    -4.335062570408685      1.017565992985448  0.995660117  0.942225402 17.205355615 19.344559363
    Var initV_SFM(N_VAR);
    initV_SFM.set_lnF(-9.306244130);
    initV_SFM.set_lmF(9.262350872);
    initV_SFM.set_nF(0.997253563);
    initV_SFM.set_mu(-1.308729418);
    initV_SFM.set_mF(0.996808765);
    initV_SFM.set_dF(0.014259761);
    initV_SFM.set_chiup(0.001204526);
    initV_SFM.set_chidown(0.000162960);
    initV_SFM.set_lchiup(1e-12);
    initV_SFM.set_lchidown(1e-12);

    //(4) pregresywne zwiększanie U=5
    Par initPar_HM4(N_PAR);
    initPar_HM4.set_n(1.6);
    initPar_HM4.set_t(-1.);
    initPar_HM4.set_tPrim(0.25);
    initPar_HM4.set_U(5.);
    initPar_HM4.set_V(-1.0);
    initPar_HM4.set_h(0.001);
    initPar_HM4.set_epsilonF(-3.0);
    initPar_HM4.set_tF(-0.0);
    initPar_HM4.set_gFg(1.);
    initPar_HM4.set_Vint(-0.0);
    initPar_HM4.set_alpha(0.0);
    initPar_HM4.set_beta(5000.);
    initPar_HM4.set_L(512);
    //-1.000000  -1.811534637  0.419289098  0.913721587 -1.242454046  0.494499990  0.210248759 -0.119498230  0.035937096 -0.000000000 -0.000000000    -4.625936195205819      0.400000000000119  0.689268276  0.609248123  0.006458028  0.389222202
    Var initV_HM4(N_VAR);
    initV_HM4.set_lnF(-1.811534637);
    initV_HM4.set_lmF(0.419289098);
    initV_HM4.set_nF(0.913721587);
    initV_HM4.set_mu(-1.242454046);
    initV_HM4.set_mF(0.494499990);
    initV_HM4.set_dF(0.210248759);
    initV_HM4.set_chiup(-0.119498230);
    initV_HM4.set_chidown(0.035937096);
    initV_HM4.set_lchiup(1e-12);
    initV_HM4.set_lchidown(1e-12);


	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_HM4;
	Var initV(N_VAR); initV = initV_HM4;

	printf("#dochodze do punktu startowego (2D V and Vint -- dokladnie)\n");

	//(1) HM z dolu L i P
	//automatic_run_h(initPar, initV, 0.05, 0.01, 0.01); printf("\n");
	//automatic_run_h(initPar, initV, 0.01, 0.001, 0.002); printf("\n");
	//automatic_run_Vint(initPar, initV, -0.0, -0.25, 0.1); printf("\n");
	//automatic_run_V(initPar, initV, -1.7, -0.5, 0.01); printf("\n");
	//automatic_run_V(initPar, initV, -0.5, -1.7, 0.01); printf("\n");
	//automatic_run_tF(initPar, initV, 0., -0.18, 0.02); printf("\n");
	//automatic_run_V(initPar, initV, -1.2, -0.5, 0.01); printf("\n");

		//automatic_run_Vint(initPar, initV, -0., -0.2, 0.05); printf("\n");
		//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
		//automatic_run_U(initPar, initV, 5., 20.0, 1.); printf("\n");
		//automatic_run_tF(initPar, initV, 0.0, -0.1, 0.01); printf("\n");

	//(2) PM z prawej
	//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
	//automatic_run_U(initPar, initV, 5., 20.0, 0.5); printf("\n");
	//initV.shake(1e-5);

	//(3) SFM z lewej
//	automatic_run_h(initPar, initV, 0.05, 0.01, 0.01); printf("\n");
//	automatic_run_h(initPar, initV, 0.01, 0.001, 0.002); printf("\n");
//	automatic_run_V(initPar, initV, -1.7, -1.5, 0.1); printf("\n");
//	automatic_run_tF(initPar, initV, 0., -0.20, 0.05); printf("\n");


	//(4) progresywne U=5
	automatic_run_V(initPar, initV, -1.0, -1.7, 0.05); printf("\n");
	//automatic_run_Vint(initPar, initV, -0.0, -0.15, 0.05); printf("\n");
	automatic_run_U(initPar, initV, 5.0, 20, 2.); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -4.0, 0.1); printf("\n");
	automatic_run_tF(initPar, initV, 0., -0.25, 0.02); printf("\n");

		//automatic_run_Vint(initPar, initV, -0.2, -0.1, 0.01); printf("\n");
		//automatic_run_V(initPar, initV, -0.0, -0.1, 0.01); printf("\n");
		//automatic_run_Vint(initPar, initV, -0.1, -0.0, 0.01); printf("\n");
		//automatic_run_tPrim(initPar, initV, 0.25, 0.0, 0.05); printf("\n");
		//automatic_run_U(initPar, initV, 20., 5.0, 0.5); printf("\n");


	initV_HM4.shake(1e-6);
	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

    //(1)
    //automatic_2Drun_hVtF(initPar, initV, 0.02, 0.0, 0.00, -1.1, -0.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_hVtF(initPar, initV, 0.02, 0.0, 0.01, -1.1, -3.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //automatic_2Drun_hVtF(initPar, initV, 0.001, 0.5, 0.01, -1.0, -4.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_hVtF(initPar, initV, 0.001, 0.5, 0.01, -1.0, -0.5, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(2)
    //automatic_2Drun_hV(initPar, initV, 0.05, 0.5, 0.002, -5.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(3)
    //automatic_2Drun_hV(initPar, initV, 0.001, 0.3, 0.01, -3.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_hV(initPar, initV, 0.001, 0.3, 0.01, -3.0, -2.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(4)
    //automatic_2Drun_hVtF(initPar, initV, 0.001, 0.3, 0.01, -1.7, -1.0, 0.01, -1.4, -1.7, -0.14);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_hVtF(initPar, initV, 0.001, 0.3, 0.01, -1.7, -3.0, 0.01, -1.4, -1.7, -0.14);  printf("\n"); initPar=oldPar; initV=oldVar;

    //automatic_2Drun_tFV(initPar, initV, -0.0, -0.3, 0.01, -2.0, -3.5, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_tFV(initPar, initV, -0.0, -0.3, 0.01, -2.0, -1.0, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;

    // zmiana tF 0-0.145 w przedziale 1-1.3 - U5
/*	automatic_run_h(initPar, initV, 0.001, 0.3, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, -(1.2-1.0)*0.145/0.3, 0.005); automatic_run_V(initPar, initV, -1.28, -1.2, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, -(1.1-1.0)*0.145/0.3, 0.005); automatic_run_V(initPar, initV, -1.28, -1.1, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, -(1.0-1.0)*0.145/0.3, 0.005); automatic_run_V(initPar, initV, -1.28, -1.0, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, 0., 0.005);                   automatic_run_V(initPar, initV, -1.28, -0.9, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, 0., 0.005);                   automatic_run_V(initPar, initV, -1.28, -0.8, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, 0., 0.005);                   automatic_run_V(initPar, initV, -1.28, -0.7, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, 0., 0.005);                   automatic_run_V(initPar, initV, -1.28, -0.6, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
	automatic_run_tF(initPar, initV, -0.145, 0., 0.005);                   automatic_run_V(initPar, initV, -1.28, -0.5, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;


	automatic_run_V(initPar, initV, -1.28, -1.4, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -1.5, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -1.6, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -1.7, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -1.8, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -1.9, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
	automatic_run_V(initPar, initV, -1.28, -2.0, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n");
*/
    // zmiana tF 0-0.2 w przedziale 1.3-1.7 - U20
/*    automatic_run_h(initPar, initV, 0.001, 0.3, 0.01); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, -(1.6-1.3)*0.21/0.4, 0.005); automatic_run_V(initPar, initV, -1.7, -1.6, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, -(1.5-1.3)*0.21/0.4, 0.005); automatic_run_V(initPar, initV, -1.7, -1.5, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, -(1.4-1.3)*0.21/0.4, 0.005); automatic_run_V(initPar, initV, -1.7, -1.4, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, 0., 0.005);                  automatic_run_V(initPar, initV, -1.7, -1.3, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, 0., 0.005);                  automatic_run_V(initPar, initV, -1.7, -1.2, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, 0., 0.005);                  automatic_run_V(initPar, initV, -1.7, -1.1, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, 0., 0.005);                  automatic_run_V(initPar, initV, -1.7, -1.0, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_tF(initPar, initV, -0.21, 0., 0.005);                  automatic_run_V(initPar, initV, -1.7, -0.9, 0.01); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
*/
    automatic_run_V(initPar, initV, -1.7, -1.8, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -1.9, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -2.0, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -2.1, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -2.2, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -2.3, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    automatic_run_V(initPar, initV, -1.7, -2.4, 0.005); automatic_run_h(initPar, initV, 0.001, 0.3, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;


	return;
}

void run_2D_realistic() {
    //(4) pregresywne zwiększanie U=5
    Par initPar_HM4(N_PAR);
    initPar_HM4.set_n(1.6);
    initPar_HM4.set_t(-1.);
    initPar_HM4.set_tPrim(0.25);
    initPar_HM4.set_U(20);
    initPar_HM4.set_V(-1.7);
    initPar_HM4.set_h(0.001);
    initPar_HM4.set_epsilonF(-3.162500);
    initPar_HM4.set_tF(-0.0);
    initPar_HM4.set_gFg(1.);
    initPar_HM4.set_Vint(-0.340000);
    initPar_HM4.set_alpha(0.0);
    initPar_HM4.set_beta(5000.);
    initPar_HM4.set_L(512);
    //1.700000 -0.000000 -3.162500 -0.340000 -2.879259767  0.925678229  0.793001643 -0.794905487  0.518721655  0.092392360 -0.108046778  0.038037089 -0.000000000  0.000000000    -5.493080987842898      0.400000000000000  0.732679523  0.490114019  0.162122813  1.159688228
    //                             -0.340000 -2.879259767  0.925678229  0.793001643 -0.794905487  0.518721655  0.092392360 -0.108046778  0.038037089 -0.000000000  0.000000000    -5.493080987842895      0.399999999999752  0.732679523  0.490114019  0.162122813  1.159688228

    Var initV_HM4(N_VAR);
    initV_HM4.set_lnF(-2.879259767);
    initV_HM4.set_lmF(0.925678229);
    initV_HM4.set_nF(0.793001643);
    initV_HM4.set_mu(-0.794905487);
    initV_HM4.set_mF(0.518721655);
    initV_HM4.set_dF(0.092392360);
    initV_HM4.set_chiup(-0.108046778);
    initV_HM4.set_chidown(0.038037089);
    initV_HM4.set_lchiup(1e-12);
    initV_HM4.set_lchidown(1e-12);

    //(4) pregresywne zwiększanie U=5
    Par initPar_HMp(N_PAR);
    initPar_HMp.set_n(1.6);
    initPar_HMp.set_t(-1.);
    initPar_HMp.set_tPrim(0.25);
    initPar_HMp.set_U(20);
    initPar_HMp.set_V(-1.27);
    initPar_HMp.set_h(0.001); //0.6 T
    initPar_HMp.set_epsilonF(-3.753750);
    initPar_HMp.set_tF(-0.27);
    initPar_HMp.set_gFg(1.);
    initPar_HMp.set_Vint(-0.254000);
    initPar_HMp.set_alpha(0.0);
    initPar_HMp.set_beta(5000.); // 0.8 K
    initPar_HMp.set_L(512);
    //-1.270000 -0.270000 -3.753750 -0.254000
    //-2.942638864  0.549302401  0.874908231 -0.758405227  0.535815216  0.075213067 -0.107219446  0.038701643 -0.003098746  0.008584798    -5.455541281670461      0.399999999999996  0.533291029  0.311120850  0.164019780  1.180139057
    Var initV_HMp(N_VAR);
    initV_HMp.set_lnF(-2.942638864);
    initV_HMp.set_lmF(0.549302401);
    initV_HMp.set_nF(0.874908231);
    initV_HMp.set_mu(-0.758405227);
    initV_HMp.set_mF(0.535815216);
    initV_HMp.set_dF(0.075213067);
    initV_HMp.set_chiup(-0.107219446);
    initV_HMp.set_chidown(0.038701643);
    initV_HMp.set_lchiup(-0.003098746);
    initV_HMp.set_lchidown(0.008584798);


	// I'm choosing start point
	Par initPar(N_PAR); initPar = initPar_HM4;
	Var initV(N_VAR); initV = initV_HM4;


	//automatic_run_Vint(initPar, initV, -0.34, A1*1.27, 0.01); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -5.5+1.7*(11./8.), 0.01); printf("\n");
	//automatic_run_V(initPar, initV, -1.7, -1.27, 0.02); printf("\n");
	//automatic_run_U(initPar, initV, 5, 20, 1); printf("\n");
	//automatic_run_Vint(initPar, initV, -0.0, -0.2*1.7, 0.03); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -5.5+1.7*(11./8.), 0.01); printf("\n");
	//automatic_run_Vint(initPar, initV, -0.34, A1*1.27, 0.01); printf("\n");

	double A1 = 0.2;
	double A2 = -11./8.;
	double B2 = -5.5;
	automatic_run_V(initPar, initV, -1.7, -0.5, 0.005); printf("\n");
	automatic_run_Vint(initPar, initV, -0.34, A1*(-0.5), 0.02); printf("\n");
	automatic_run_epsilonF(initPar, initV, -3.1625, A2*(-0.5)+B2, 0.1); printf("\n");

	//automatic_run_tF(initPar, initV, -0.0, -0.3, 0.01); printf("\n");

	//automatic_run_p(initPar, initV, -0.5, -0.8, 0.001); printf("\n");
	//automatic_run_p(initPar, initV, -2.5, -1.5, 0.005); printf("\n");

	automatic_run_h(initPar, initV, 0.001, 0.0, 0.001); printf("\n");

	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

    //(1)
    //automatic_2Drun_ptF(initPar, initV, -1.7, -0.5, 0.01, -0.0, -0.5, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_2Drun_ptF(initPar, initV, -1.7, -3.0, 0.01, -0.0, -0.5, 0.01);  printf("\n"); initPar=oldPar; initV=oldVar;


   //(2)
   //automatic_2Drun_hp(initPar, initV, 0.001, 0.2, 0.01, -1.27, -0.8, 0.01, -1.0, -1.3, -0.3);  printf("\n"); initPar=oldPar; initV=oldVar;
   //automatic_2Drun_hp(initPar, initV, 0.001, 0.3, 0.01, -1.27, -2.5, 0.01, -1.0, -1.3, -0.3);  printf("\n"); initPar=oldPar; initV=oldVar;

   //automatic_2Drun_hp(initPar, initV, 0.001, 0.15, 0.002, -0.8, -1.3, 0.001, -1.0, -1.3, -0.3);  printf("\n"); initPar=oldPar; initV=oldVar;

   //automatic_2Drun_ph(initPar, initV, -1.27, -1.5, 0.002, 0.001, 0.15, 0.001, -1.0, -1.3, -0.3);  printf("\n"); initPar=oldPar; initV=oldVar;
   //automatic_2Drun_ph(initPar, initV, -1.27, -0.9, 0.002, 0.001, 0.15, 0.001, -1.0, -1.3, -0.3);  printf("\n"); initPar=oldPar; initV=oldVar;

    //(3)
    automatic_run_p(initPar, initV, -0.5, -3.0, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_run_p(initPar, initV, -1.27, -0.5, 0.001); printf("\n"); initPar=oldPar; initV=oldVar;


	return;
}




void run_Belitz() {

    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

	// (1)
    Par initPar_Belitz_g2_HM(N_PAR);
    initPar_Belitz_g2_HM.set_n(1.8);
    initPar_Belitz_g2_HM.set_t(-1.);
    initPar_Belitz_g2_HM.set_tPrim(0.25);
    initPar_Belitz_g2_HM.set_U(5.);
    initPar_Belitz_g2_HM.set_V(-1.2);
    initPar_Belitz_g2_HM.set_h(0.0);
    initPar_Belitz_g2_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2_HM.set_tF(-0.0);
    initPar_Belitz_g2_HM.set_gFg(2./2.);
    initPar_Belitz_g2_HM.set_Vint(-0.0);
    initPar_Belitz_g2_HM.set_alpha(0.0);
    initPar_Belitz_g2_HM.set_beta(5000.);
    initPar_Belitz_g2_HM.set_L(512);
    //        -2.233439717  0.242535105  0.957803266 -0.877477471  0.257455342  0.294530643 -0.130743575 -0.005223736  0.000000000  0.000000000    -5.060748275674911      0.200000000000163  0.706205875  0.692179583  0.004533367  0.063157986
    Var initV_Belitz_g2_HM(N_VAR);
    initV_Belitz_g2_HM.set_lnF(-2.233439717);
    initV_Belitz_g2_HM.set_lmF(0.242535105);
    initV_Belitz_g2_HM.set_nF(0.957803266);
    initV_Belitz_g2_HM.set_mu(-0.877477471);
    initV_Belitz_g2_HM.set_mF(0.257455342);
    initV_Belitz_g2_HM.set_dF(0.294530643);
    initV_Belitz_g2_HM.set_chiup(-0.130743575);
    initV_Belitz_g2_HM.set_chidown(-0.005223736);
    initV_Belitz_g2_HM.set_lchiup(1e-12);
    initV_Belitz_g2_HM.set_lchidown(1e-12);


    //(2)
    Par initPar_Belitz_g2_PM(N_PAR);
    initPar_Belitz_g2_PM.set_n(1.6);
    initPar_Belitz_g2_PM.set_t(-1.);
    initPar_Belitz_g2_PM.set_tPrim(0.25);
    initPar_Belitz_g2_PM.set_U(5.);
    initPar_Belitz_g2_PM.set_V(-1.2);
    initPar_Belitz_g2_PM.set_h(0.0);
    initPar_Belitz_g2_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2_PM.set_tF(-0.0);
    initPar_Belitz_g2_PM.set_gFg(2./2.);
    initPar_Belitz_g2_PM.set_Vint(-0.0);
    initPar_Belitz_g2_PM.set_alpha(0.0);
    initPar_Belitz_g2_PM.set_beta(5.);
    initPar_Belitz_g2_PM.set_L(256);
    //5.000000  -1.839782246 -0.000000000  0.904142805 -1.412946405 -0.000000000  0.242703635 -0.030369455 -0.030369455  0.000000000  0.000000000    -4.889214887016995     -0.000000000000036  0.642242166  0.642242166  0.052059433  0.052059433
    Var initV_Belitz_g2_PM(N_VAR);
    initV_Belitz_g2_PM.set_lnF(-2.233439717);
    initV_Belitz_g2_PM.set_lmF(0.242535105);
    initV_Belitz_g2_PM.set_nF(0.957803266);
    initV_Belitz_g2_PM.set_mu(-0.877477471);
    initV_Belitz_g2_PM.set_mF(0.257455342);
    initV_Belitz_g2_PM.set_dF(0.294530643);
    initV_Belitz_g2_PM.set_chiup(-0.130743575);
    initV_Belitz_g2_PM.set_chidown(-0.005223736);
    initV_Belitz_g2_PM.set_lchiup(1e-12);
    initV_Belitz_g2_PM.set_lchidown(1e-12);

    // h != 0

    // (B2-001-0-02-PM) V=-1.2, h=0.01, Vint=0, tF=-1.0, t'=0.25
    Par initPar_Bh_V12Vint0tF10_PM(N_PAR);
    initPar_Bh_V12Vint0tF10_PM.set_n(1.8);
    initPar_Bh_V12Vint0tF10_PM.set_t(-1.);
    initPar_Bh_V12Vint0tF10_PM.set_tPrim(0.25);
    initPar_Bh_V12Vint0tF10_PM.set_U(5.);
    initPar_Bh_V12Vint0tF10_PM.set_V(-1.2);
    initPar_Bh_V12Vint0tF10_PM.set_h(0.1);
    initPar_Bh_V12Vint0tF10_PM.set_epsilonF(-3.0);
    initPar_Bh_V12Vint0tF10_PM.set_tF(-1.0);
    initPar_Bh_V12Vint0tF10_PM.set_gFg(1.);
    initPar_Bh_V12Vint0tF10_PM.set_Vint(-0.0);
    initPar_Bh_V12Vint0tF10_PM.set_alpha(0.0);
    initPar_Bh_V12Vint0tF10_PM.set_beta(5000.);
    initPar_Bh_V12Vint0tF10_PM.set_L(512);
    //    -1.000000  -2.300566420  0.084871374  0.953227112 -0.780971948  0.058877743  0.383733417  0.172028331  0.169738343  0.000003503  0.000003550    -5.698077386570055      0.084453964702879  0.898840381  0.897713476  0.000214167  0.004720089
    Var initV_Bh_V12Vint0tF10_PM(N_VAR);
    initV_Bh_V12Vint0tF10_PM.set_lnF(-2.300566420);
    initV_Bh_V12Vint0tF10_PM.set_lmF(0.084871374);
    initV_Bh_V12Vint0tF10_PM.set_nF(0.953227112);
    initV_Bh_V12Vint0tF10_PM.set_mu(-0.780971948);
    initV_Bh_V12Vint0tF10_PM.set_mF(0.058877743);
    initV_Bh_V12Vint0tF10_PM.set_dF(0.383733417);
    initV_Bh_V12Vint0tF10_PM.set_chiup(0.172028331);
    initV_Bh_V12Vint0tF10_PM.set_chidown(0.169738343);
    initV_Bh_V12Vint0tF10_PM.set_lchiup(0.000003503);
    initV_Bh_V12Vint0tF10_PM.set_lchidown(0.000003503);


	// I'm choosing start point

	Par initPar(N_PAR); initPar = initPar_Bh_V12Vint0tF10_PM;
	Var initV(N_VAR); initV = initV_Bh_V12Vint0tF10_PM;

	printf("#dochodze do punktu startowego (Vtg)\n");

	automatic_run_tF(initPar, initV, -1.0, 0.0, 0.01); printf("\n");
	automatic_run_n(initPar, initV, 1.8, 1.60, 0.01); printf("\n");
	automatic_run_V(initPar, initV, -1.20, -2.0, 0.01); printf("\n");
	automatic_run_h(initPar, initV, 0.1, 0.01, 0.002); printf("\n");
	automatic_run_T(initPar, initV, 1, 5, 1); printf("\n");
	//automatic_run_gFg(initPar, initV, 1.00, 0.25, 0.01); printf("\n");


	//automatic_run_Vint(initPar, initV, -1.00, -0.8, 0.01); printf("\n");
	//automatic_run_tPrim(initPar, initV, 0.25, 0.00, 0.05); printf("\n");
	//automatic_run_tF(initPar, initV, -0.00, -0.10, 0.001); printf("\n");
	//automatic_run_U(initPar, initV, 20, 5.0, 1.0); printf("\n");
	//automatic_run_h(initPar, initV, 0., 0.1, 0.01); printf("\n");
	//automatic_run_epsilonF(initPar, initV, -3.0, -2.35, 0.05); printf("\n");
	//automatic_run_VtoP(initPar, initV, -1.75, -2.3, 0.01,  -12./5., -36./5.); printf("\n");
	//automatic_run_beta(initPar, initV, 500, 1, 5); printf("\n");
	//automatic_run_n(initPar, initV, 1.8, 1.5, 0.01); printf("\n");


	printf("#Jestem w punkcie startowym\n");
    Par oldPar = initPar;
    Var oldVar = initV;

	automatic_run_beta(initPar, initV, 5, 20, 1); printf("\n");
	automatic_run_beta(initPar, initV, 20, 100, 5); printf("\n");
	automatic_run_beta(initPar, initV, 100, 1000, 10); printf("\n");
	automatic_run_beta(initPar, initV, 100, 5000, 100); printf("\n");
	automatic_run_V(initPar, initV, -2.60, -2.0, 0.01); printf("\n");

    //automatic_run_beta(initPar, initV, 1000, 100, 10); printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_run_beta(initPar, initV, 100, 10, 1); printf("\n"); initPar=oldPar; initV=oldVar;
    //automatic_run_beta(initPar, initV, 10, 1, 0.1); printf("\n"); initPar=oldPar; initV=oldVar;


    printf("Koniec\n");
}

void run_Belitz_automatic() {

    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

	// (1) HM, h=0
    Par initPar_Belitz_g2_HM(N_PAR);
    initPar_Belitz_g2_HM.set_n(1.6);
    initPar_Belitz_g2_HM.set_t(-1.);
    initPar_Belitz_g2_HM.set_tPrim(0.25);
    initPar_Belitz_g2_HM.set_U(5.);
    initPar_Belitz_g2_HM.set_V(-2.0);
    initPar_Belitz_g2_HM.set_h(0.0);
    initPar_Belitz_g2_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2_HM.set_tF(-0.0);
    initPar_Belitz_g2_HM.set_gFg(2./2.);
    initPar_Belitz_g2_HM.set_Vint(-0.0);
    initPar_Belitz_g2_HM.set_alpha(0.0);
    initPar_Belitz_g2_HM.set_beta(5000.);
    initPar_Belitz_g2_HM.set_L(512);
    //-2.000000  -1.970540748  0.657285840  0.877897261 -2.059200477  0.429967158  0.297045327 -0.085473185  0.056446699  0.000000000  0.000000000    -5.857241236298249      0.399999999999973  0.912321747  0.885837291  0.008605689  0.123639248
    Var initV_Belitz_g2_HM(N_VAR);
    initV_Belitz_g2_HM.set_lnF(-1.970540748);
    initV_Belitz_g2_HM.set_lmF(0.657285840);
    initV_Belitz_g2_HM.set_nF(0.877897261);
    initV_Belitz_g2_HM.set_mu(-2.059200477);
    initV_Belitz_g2_HM.set_mF(0.429967158);
    initV_Belitz_g2_HM.set_dF(0.297045327);
    initV_Belitz_g2_HM.set_chiup(-0.085473185);
    initV_Belitz_g2_HM.set_chidown(0.056446699);
    initV_Belitz_g2_HM.set_lchiup(1e-12);
    initV_Belitz_g2_HM.set_lchidown(1e-12);


    //(2) PM, h=0
    Par initPar_Belitz_g2_PM(N_PAR);
    initPar_Belitz_g2_PM.set_n(1.6);
    initPar_Belitz_g2_PM.set_t(-1.);
    initPar_Belitz_g2_PM.set_tPrim(0.25);
    initPar_Belitz_g2_PM.set_U(5.);
    initPar_Belitz_g2_PM.set_V(-2.0);
    initPar_Belitz_g2_PM.set_h(0.0);
    initPar_Belitz_g2_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2_PM.set_tF(-0.0);
    initPar_Belitz_g2_PM.set_gFg(2./2.);
    initPar_Belitz_g2_PM.set_Vint(-0.0);
    initPar_Belitz_g2_PM.set_alpha(0.0);
    initPar_Belitz_g2_PM.set_beta(5000.);
    initPar_Belitz_g2_PM.set_L(512);
    //-2.000000  -1.862453523  0.000000000  0.852036257 -2.017313801  0.000000000  0.309279281  0.032097262  0.032097262 -0.000000000  0.000000000    -5.844957750254139      0.000000000000030  0.870846795  0.870846795  0.024237170  0.024237170
    Var initV_Belitz_g2_PM(N_VAR);
    initV_Belitz_g2_PM.set_lnF(-1.862453523);
    initV_Belitz_g2_PM.set_lmF(1e-12);
    initV_Belitz_g2_PM.set_nF(0.852036257);
    initV_Belitz_g2_PM.set_mu(-2.017313801);
    initV_Belitz_g2_PM.set_mF(1e-12);
    initV_Belitz_g2_PM.set_dF(0.309279281);
    initV_Belitz_g2_PM.set_chiup(0.0320972625);
    initV_Belitz_g2_PM.set_chidown(0.032097262);
    initV_Belitz_g2_PM.set_lchiup(1e-12);
    initV_Belitz_g2_PM.set_lchidown(1e-12);


	// I'm choosing start point
	Par parHM = initPar_Belitz_g2_HM;
	Var varHM = initV_Belitz_g2_HM;
	Par parPM = initPar_Belitz_g2_PM;
	Var varPM = initV_Belitz_g2_PM;

	// First shoot
	Res resHM(N_VAR);
	RootGSL rootHM(parHM, function, resHM);
	if(rootHM.Solve(varHM) != GSL_SUCCESS) { printf("First shot is not good (HM).\n"); return; }
	Var oldHM(*resHM.get_V());
	double OLD_HM_E = resHM.glob.Energy;
	double OLD_HM_m = resHM.glob.magnetization;

	Res resPM(N_VAR);
	RootGSL rootPM(parPM, function, resPM);
	if(rootPM.Solve(varPM) != GSL_SUCCESS) { printf("First shot is not good (PM).\n"); return; }
	Var oldPM(*resPM.get_V());
	double OLD_PM_E = resPM.glob.Energy;
	double OLD_PM_m = resPM.glob.magnetization;

	// Going to the starting point
	printf("#dochodze do punktu startowego\n");
	automatic_run_h(parHM, varHM, 0.0, 0.001, 0.001);
	//automatic_run_T(parHM, varHM, 0.1, 1., 0.1);
	automatic_run_V(parHM, varHM, -2., -3., 0.02);
	automatic_run_V(parHM, varHM, -3., -2., 0.02);

	return;

	automatic_run_T(parHM, varHM, 1., 15, 1.);
	automatic_run_T(parPM, varPM, 1., 15, 1.);

	// LABELS
	printf("#automatic_Belitz\n");
	printf("#HM: "); parHM.print_verboten();
	printf("#PM: "); parPM.print_verboten();
	printf("#init_varHM: "); varHM.print(); printf("\n");
	printf("#init_varPM: "); varPM.print(); printf("\n");
	printf("#V           "); resHM.print_label(); resPM.print_label(); printf("\n");
	fflush(stdout);

	// RUN (V)
	const double start = -2.0;
	const double stop = -2.6; // maximum
	double step = 0.01;

	varHM = oldHM;
	varPM = oldPM;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	double current_x = start;
	while(1) {
		parHM.set_V(current_x);
		parPM.set_V(current_x);
		varHM.shake(); varPM.shake();

		int sucessHM = rootHM.Solve(varHM);
		double HM_E = resHM.glob.Energy;
		double HM_m = resHM.glob.magnetization;
		int sucessPM = rootPM.Solve(varPM);
		double PM_E = resPM.glob.Energy;
		double PM_m = resPM.glob.magnetization;

		// if there is problem to obtain solution, take smaller step
		if(sucessHM != GSL_SUCCESS || sucessPM != GSL_SUCCESS) {
			if(myabs(step/adapt_step_reduction) >=  adapt_min_step) {
				step /= adapt_step_reduction;
				printf("          #NO GSL_SUCCESS -> smaller step and again! (HM=%d, PM=%d, SUCESS=%d).\n", sucessHM, sucessPM, GSL_SUCCESS);
				continue;
			} else {
				printf("          #NO GSL_SUCCESS -> step too small (%f, %e). Break the misery!\n\n", step, step/adapt_step_reduction);
				break;
			}
		}

		// if too big jump of magnetization, we might jump to other phase
		if(myabs(HM_m-OLD_HM_m) > adapt_max_m_difference) {
			if(myabs(step/adapt_step_reduction) >=  adapt_min_step) {
				step /= adapt_step_reduction;
				printf("          #Big jump of magnetization %f -> %f smaller step and again!\n", OLD_HM_m, HM_m);
				//rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
				continue;
			} else {
				printf("          #Big jump of magnetization %f -> %f and the step too small (%f, %e). Break the misery!\n\n", OLD_HM_m, HM_m, step, step/adapt_step_reduction);
				break;
			}
		}

		// special case, if PM starts winning
		if(PM_E < HM_E && myabs(PM_m - HM_m) > adapt_min_m_difference) {
			if(myabs(step/adapt_step_reduction) >=  adapt_min_step) {
				step /= adapt_step_reduction;
				printf("#I got I order transition between HM and PM!\n");
				printf("          #PM_E < HM_E -> but smaller step is needed! T=%f beta=%f V=%f step=%f: ", coeff_T/parHM.beta(), parHM.beta(), parHM.V(), step);
				rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
				continue;
			} else {
				printf("          #"); rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
				printf("#PM_E < HM_E -> I got I order transition between HM and PM\n");
				printf("#V in (%f, %f)\n\n", current_x, current_x + step);
				break;
			}
		}
		// special case, when HM jumped to PM
		if(myabs(PM_m - HM_m) < adapt_min_m_difference) { // we do have jump or II order transition
			if(myabs(step/adapt_step_reduction) >=  adapt_min_step) {
				step /= adapt_step_reduction;
				printf("          #PM_m = HM_m -> smaller step! T=%f beta=%f V=%f step=%f:", coeff_T/parHM.beta(), parHM.beta(), parHM.V(), step);
				printf("PM: E=%e, m=%e | HM: E=%e, m=%e, E_PM-E_HM=%e\n", resPM.glob.Energy, resPM.glob.magnetization, resHM.glob.Energy, resHM.glob.magnetization, resPM.glob.Energy-resHM.glob.magnetization);
				printf("          #"); rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
				continue;
			} else {
				printf("          #"); rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
				printf("#PM_m = HM_m -> I got II order transition or jump between HM and PM\n");
				printf("#V in (%f, %f)\n\n", current_x, current_x + step);
				break;
			}
		}

		// if you are here, it works, you can print stuff and as a starting point use the new variables
		current_x += step;
		printf("%f  %f ", parHM.V(), step);
		rootHM.print();
		printf(" -2  ");
		rootPM.print(); printf("\n"); fflush(stdout);
		varHM.set(resHM.get_V());
		varPM.set(resPM.get_V());

		// decide if you should change the step
		int make_the_step_bigger = 0;
		int make_the_step_smaller = 0;
		double x, y;
		for(int k=0; k<6; k++) {
			//fork
			if(k==0) { x = resPM.get_V()->mu(); y = oldPM.mu(); }
			else if(k==1) { x = resHM.get_V()->mu(); y = oldHM.mu(); }
			else if(k==2) { x = PM_m; y = OLD_PM_m; }
			else if(k==3) { x = HM_m; y = OLD_HM_m; }
			else if(k==4) { x = PM_E; y = OLD_PM_E; }
			else if(k==5) { x = HM_E; y = OLD_HM_E; }

			if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
			else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
		}

		if(make_the_step_smaller > 0) {
			step /= adapt_step_reduction;
		}
		else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
			step *= adapt_step_reduction;
		}

		// am I too far?
		if( (step > 0 && current_x > stop) || (step < 0 && current_x < stop)) {
			printf("#I'm too far\n");
			break;
		}

		// if here, it means we are going around again
		current_x += step;
		// copy new variables to OLD
		oldHM.set(resHM.get_V());
		OLD_HM_m = HM_m;
		OLD_HM_E = HM_E;
		oldPM.set(resPM.get_V());
		OLD_PM_m = PM_m;
		OLD_PM_E = PM_E;
	}
	printf("#end automatic_run_Belitz_automatic\n\n\n");
	fflush(stdout);
}

int automatic_Belitz_2ways(double startg, double starth, double startT, double startHM=-2.0, double startPM=-2.5, int startL=512) {
    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

	printf("# start automatic_Belitz_2ways: h = %f, start HM V = %f, start PM V = %f, start T = %f, start L = %d\n", starth, startHM, startPM, startT, startL);

	// (1) HM, h=0.01
    Par initPar_Belitz_g2h001_HM(N_PAR);
    initPar_Belitz_g2h001_HM.set_n(1.6);
    initPar_Belitz_g2h001_HM.set_t(-1.);
    initPar_Belitz_g2h001_HM.set_tPrim(0.25);
    initPar_Belitz_g2h001_HM.set_U(5.);
    initPar_Belitz_g2h001_HM.set_V(-2.0);
    initPar_Belitz_g2h001_HM.set_h(0.01);
    initPar_Belitz_g2h001_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2h001_HM.set_tF(-0.0);
    initPar_Belitz_g2h001_HM.set_gFg(2./2.);
    initPar_Belitz_g2h001_HM.set_Vint(-0.0);
    initPar_Belitz_g2h001_HM.set_alpha(0.0);
    initPar_Belitz_g2h001_HM.set_beta(5000.);
    initPar_Belitz_g2h001_HM.set_L(startL);
    //-2.000000  -1.970543060  0.657282879  0.877897786 -2.049074800  0.429965683  0.297045779 -0.085473284  0.056450889  0.000000000 -0.000000000    -5.861244735939589      0.400000000000001  0.912321254  0.885836939  0.008605632  0.123638526
    Var initV_Belitz_g2h001_HM(N_VAR);
    initV_Belitz_g2h001_HM.set_lnF(-1.970543060);
    initV_Belitz_g2h001_HM.set_lmF(0.657282879);
    initV_Belitz_g2h001_HM.set_nF(0.877897786);
    initV_Belitz_g2h001_HM.set_mu(-2.049074800);
    initV_Belitz_g2h001_HM.set_mF(0.429965683);
    initV_Belitz_g2h001_HM.set_dF(0.297045779);
    initV_Belitz_g2h001_HM.set_chiup(-0.085473284);
    initV_Belitz_g2h001_HM.set_chidown(0.056450889);
    initV_Belitz_g2h001_HM.set_lchiup(1e-12);
    initV_Belitz_g2h001_HM.set_lchidown(1e-12);

    Par initPar_Belitz_g67h001_HM(N_PAR);
    initPar_Belitz_g67h001_HM.set_n(1.6);
    initPar_Belitz_g67h001_HM.set_t(-1.);
    initPar_Belitz_g67h001_HM.set_tPrim(0.25);
    initPar_Belitz_g67h001_HM.set_U(5.);
    initPar_Belitz_g67h001_HM.set_V(-2.0);
    initPar_Belitz_g67h001_HM.set_h(0.01);
    initPar_Belitz_g67h001_HM.set_epsilonF(-3.0);
    initPar_Belitz_g67h001_HM.set_tF(-0.0);
    initPar_Belitz_g67h001_HM.set_gFg(3./7.); // (6./7.)/2.
    initPar_Belitz_g67h001_HM.set_Vint(-0.0);
    initPar_Belitz_g67h001_HM.set_alpha(0.0);
    initPar_Belitz_g67h001_HM.set_beta(5000.);
    initPar_Belitz_g67h001_HM.set_L(startL);
    //-2.000000  -1.970066282  0.654812451  0.877766382 -2.053826532  0.428661278  0.297146816 -0.085606406  0.056608714 -0.000000000 -0.000000000    -5.858788011575221      0.400000000000000  0.912110894  0.885664309  0.008442744  0.123238692
    Var initV_Belitz_g67h001_HM(N_VAR);
    initV_Belitz_g67h001_HM.set_lnF(-1.970543060);
    initV_Belitz_g67h001_HM.set_lmF(0.657282879);
    initV_Belitz_g67h001_HM.set_nF(0.877897786);
    initV_Belitz_g67h001_HM.set_mu(-2.049074800);
    initV_Belitz_g67h001_HM.set_mF(0.429965683);
    initV_Belitz_g67h001_HM.set_dF(0.297045779);
    initV_Belitz_g67h001_HM.set_chiup(-0.085473284);
    initV_Belitz_g67h001_HM.set_chidown(0.056450889);
    initV_Belitz_g67h001_HM.set_lchiup(1e-12);
    initV_Belitz_g67h001_HM.set_lchidown(1e-12);

    Par initPar_Belitz_g67h085_HM(N_PAR);
    initPar_Belitz_g67h085_HM.set_n(1.6);
    initPar_Belitz_g67h085_HM.set_t(-1.);
    initPar_Belitz_g67h085_HM.set_tPrim(0.25);
    initPar_Belitz_g67h085_HM.set_U(5.);
    initPar_Belitz_g67h085_HM.set_V(-2.0);
    initPar_Belitz_g67h085_HM.set_h(0.085);
    initPar_Belitz_g67h085_HM.set_epsilonF(-3.0);
    initPar_Belitz_g67h085_HM.set_tF(-0.0);
    initPar_Belitz_g67h085_HM.set_gFg(3./7.); // (6./7.)/2.
    initPar_Belitz_g67h085_HM.set_Vint(-0.0);
    initPar_Belitz_g67h085_HM.set_alpha(0.0);
    initPar_Belitz_g67h085_HM.set_beta(5000.);
    initPar_Belitz_g67h085_HM.set_L(startL);
    //0.085000  -1.966521808  0.636344354  0.876790655 -2.013753826  0.418826868  0.297888073 -0.086595936  0.057840653  0.000000000  0.000000000    -5.870627418214124      0.399999999998993  0.910532592  0.884382253  0.007269892  0.120243363
    Var initV_Belitz_g67h085_HM(N_VAR);
    initV_Belitz_g67h085_HM.set_lnF(-1.966521808);
    initV_Belitz_g67h085_HM.set_lmF(0.636344354);
    initV_Belitz_g67h085_HM.set_nF(0.876790655);
    initV_Belitz_g67h085_HM.set_mu(-2.013753826);
    initV_Belitz_g67h085_HM.set_mF(0.418826868);
    initV_Belitz_g67h085_HM.set_dF(0.297888073);
    initV_Belitz_g67h085_HM.set_chiup(-0.086595936);
    initV_Belitz_g67h085_HM.set_chidown(0.057840653);
    initV_Belitz_g67h085_HM.set_lchiup(1e-12);
    initV_Belitz_g67h085_HM.set_lchidown(1e-12);

    //(2) PM, h=0.01
    Par initPar_Belitz_g2h001_PM(N_PAR);
    initPar_Belitz_g2h001_PM.set_n(1.6);
    initPar_Belitz_g2h001_PM.set_t(-1.);
    initPar_Belitz_g2h001_PM.set_tPrim(0.25);
    initPar_Belitz_g2h001_PM.set_U(5.);
    initPar_Belitz_g2h001_PM.set_V(-3.0);
    initPar_Belitz_g2h001_PM.set_h(0.01);
    initPar_Belitz_g2h001_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2h001_PM.set_tF(-0.0);
    initPar_Belitz_g2h001_PM.set_gFg(2./2.);
    initPar_Belitz_g2h001_PM.set_Vint(-0.0);
    initPar_Belitz_g2h001_PM.set_alpha(0.0);
    initPar_Belitz_g2h001_PM.set_beta(5000.);
    initPar_Belitz_g2h001_PM.set_L(startL);
    //-3.000000  -1.900647644  0.035014344  0.832477123 -2.862847429  0.020821503  0.340072775  0.040879598  0.047596211  0.000000000 -0.000000000    -7.322624984355449      0.022313523402390  0.941678714  0.940835070  0.009438461  0.012752674
    Var initV_Belitz_g2h001_PM(N_VAR);
    initV_Belitz_g2h001_PM.set_lnF(-1.900647644);
    initV_Belitz_g2h001_PM.set_lmF(0.035014344);
    initV_Belitz_g2h001_PM.set_nF(0.832477123);
    initV_Belitz_g2h001_PM.set_mu(-2.862847429);
    initV_Belitz_g2h001_PM.set_mF(0.020821503);
    initV_Belitz_g2h001_PM.set_dF(0.340072775);
    initV_Belitz_g2h001_PM.set_chiup(0.040879598);
    initV_Belitz_g2h001_PM.set_chidown(0.047596211);
    initV_Belitz_g2h001_PM.set_lchiup(1e-12);
    initV_Belitz_g2h001_PM.set_lchidown(1e-12);

    Par initPar_Belitz_g67h001_PM(N_PAR);
    initPar_Belitz_g67h001_PM.set_n(1.6);
    initPar_Belitz_g67h001_PM.set_t(-1.);
    initPar_Belitz_g67h001_PM.set_tPrim(0.25);
    initPar_Belitz_g67h001_PM.set_U(5.);
    initPar_Belitz_g67h001_PM.set_V(-2.5);
    initPar_Belitz_g67h001_PM.set_h(0.01);
    initPar_Belitz_g67h001_PM.set_epsilonF(-3.0);
    initPar_Belitz_g67h001_PM.set_tF(-0.0);
    initPar_Belitz_g67h001_PM.set_gFg(3./7.);
    initPar_Belitz_g67h001_PM.set_Vint(-0.0);
    initPar_Belitz_g67h001_PM.set_alpha(0.0);
    initPar_Belitz_g67h001_PM.set_beta(5000.);
    initPar_Belitz_g67h001_PM.set_L(startL);
    //-2.500000  -1.885022167  0.036580137  0.840278202 -2.426104337  0.023677068  0.327866683  0.035226276  0.043117092 -0.000000000 -0.000000000    -6.571921070105477      0.024690032215733  0.916738882  0.915435555  0.013353316  0.018459126
    Var initV_Belitz_g67h001_PM(N_VAR);
    initV_Belitz_g67h001_PM.set_lnF(-1.885022167);
    initV_Belitz_g67h001_PM.set_lmF(0.036580137);
    initV_Belitz_g67h001_PM.set_nF(0.840278202);
    initV_Belitz_g67h001_PM.set_mu(-2.426104337);
    initV_Belitz_g67h001_PM.set_mF(0.023677068);
    initV_Belitz_g67h001_PM.set_dF(0.327866683);
    initV_Belitz_g67h001_PM.set_chiup(0.035226276);
    initV_Belitz_g67h001_PM.set_chidown(0.043117092);
    initV_Belitz_g67h001_PM.set_lchiup(1e-12);
    initV_Belitz_g67h001_PM.set_lchidown(1e-12);

    Par initPar_Belitz_g67h085_PM(N_PAR);
    initPar_Belitz_g67h085_PM.set_n(1.6);
    initPar_Belitz_g67h085_PM.set_t(-1.);
    initPar_Belitz_g67h085_PM.set_tPrim(0.25);
    initPar_Belitz_g67h085_PM.set_U(5.);
    initPar_Belitz_g67h085_PM.set_V(-3.0);
    initPar_Belitz_g67h085_PM.set_h(0.085);
    initPar_Belitz_g67h085_PM.set_epsilonF(-3.0);
    initPar_Belitz_g67h085_PM.set_tF(-0.0);
    initPar_Belitz_g67h085_PM.set_gFg(3./7.);
    initPar_Belitz_g67h085_PM.set_Vint(-0.0);
    initPar_Belitz_g67h085_PM.set_alpha(0.0);
    initPar_Belitz_g67h085_PM.set_beta(5000.);
    initPar_Belitz_g67h085_PM.set_L(startL);
    //0.085000  -1.904781915  0.127364682  0.833638992 -2.863625240  0.075402638  0.339724286  0.027989390  0.056543413 -0.000000000  0.000000000    -7.324461979218865      0.089324326146737  0.943165280  0.940136496  0.005732781  0.017658937
    Var initV_Belitz_g67h085_PM(N_VAR);
    initV_Belitz_g67h085_PM.set_lnF(-1.904781915);
    initV_Belitz_g67h085_PM.set_lmF(0.127364682);
    initV_Belitz_g67h085_PM.set_nF(0.833638992);
    initV_Belitz_g67h085_PM.set_mu(-2.863625240);
    initV_Belitz_g67h085_PM.set_mF(0.075402638);
    initV_Belitz_g67h085_PM.set_dF(0.339724286);
    initV_Belitz_g67h085_PM.set_chiup(0.027989390);
    initV_Belitz_g67h085_PM.set_chidown(0.056543413);
    initV_Belitz_g67h085_PM.set_lchiup(1e-12);
    initV_Belitz_g67h085_PM.set_lchidown(1e-12);


	// I'm choosing start points
    Par parHM = initPar_Belitz_g2h001_HM;
	Var varHM = initV_Belitz_g2h001_HM;
	Par parPM = initPar_Belitz_g2h001_PM;
	Var varPM = initV_Belitz_g2h001_PM;

	Res resHM(N_VAR);
	RootGSL rootHM(parHM, function, resHM);
	Res resPM(N_VAR);
	RootGSL rootPM(parPM, function, resPM);

	// *********************************************************************************** //
	// ********************** Going to the starting point ******************************** //
	// *********************************************************************************** //

	printf("#dochodze do punktu startowego\n");

	//varHM.shake(); varPM.shake();
	automatic_run_n(parHM, varHM, 1.6, 1.7, 0.01); parHM.set_n(1.7);
	automatic_run_n(parPM, varPM, 1.6, 1.7, 0.01); parPM.set_n(1.7);


	varHM.shake(); varPM.shake();
	automatic_run_V(parHM, varHM, -2., startHM, 0.02); parHM.set_V(startHM);
	automatic_run_V(parPM, varPM, -3.0, startPM, 0.02); parPM.set_V(startPM);

	varHM.shake(); varPM.shake();
	automatic_run_T(parHM, varHM, 0.1, startT, 0.2); parHM.set_beta(coeff_T/startT);
	automatic_run_T(parPM, varPM, 0.1, startT, 0.2); parPM.set_beta(coeff_T/startT);

	varHM.shake(); varPM.shake();
	automatic_run_gFg(parHM, varHM, 2./2., startg/2., 0.02); parHM.set_gFg(startg/2.);
	automatic_run_gFg(parPM, varPM, 2./2., startg/2., 0.02); parPM.set_gFg(startg/2.);

	varHM.shake(); varPM.shake();
	automatic_run_h(parHM, varHM, 0.01, starth/coeff_H, 0.002); parHM.set_h(starth/coeff_H);
	automatic_run_h(parPM, varPM, 0.01, starth/coeff_H, 0.002); parPM.set_h(starth/coeff_H);

	//robie kobie PM
	Par parPMcp = parPM;
	Var varPMcp = varPM;

	printf("#Jestem w punkcie startowym\n");

	// PARAMETERS
	const double start1 = startHM;
	const double stop1 = startPM; // maximum
	double step1 = 0.01;

	const double start2 = startPM;
	const double stop2 = startHM; // maximum
	double step2 = 0.01;

	// *********************************************************************************** //
	// *********************************************************************************** //

	// (1) I'm pushing the HM as far as I can

	// first shoot
	varHM.shake();
	if(rootHM.Solve(varHM) != GSL_SUCCESS) { printf("# (0) First shot is not good (HM).\n"); return -1; }
	Var oldHM(*resHM.get_V());
	double OLD_HM_E = resHM.glob.Energy;
	double OLD_HM_m = resHM.glob.magnetization;

	// labels
	printf("# Belitz automatic 2 ways: pushing the HM solution (|V| increase)\n");
	printf("# HM: "); parHM.print_verboten();
	printf("# init_varHM: "); varHM.print(); printf("\n");
	printf("# V            h        h(T)       beta       T       "); resHM.print_label(); printf("\n");
	printf("%.9f %f %f %f %f", parHM.V(), parHM.h(), coeff_H*parHM.h(), parHM.beta(), coeff_T/parHM.beta());
	rootHM.print(); printf("\n");

	// run
	int LOOPS1 = int((stop1-start1)/step1);
	if(LOOPS1 < 0) { LOOPS1 = -LOOPS1; step1 = -step1; }
	double current_x1 = start1;
	while(1) {
		fflush(stdout);
		parHM.set_V(current_x1+step1);
		varHM.shake();
		int sucessHM = rootHM.Solve(varHM);

		// if there is problem to obtain solution, take smaller step
		if(sucessHM != GSL_SUCCESS) {
			if(myabs(step1/adapt_step_reduction) >=  adapt_min_step) {
				step1 /= adapt_step_reduction;
				printf("          # (1) NO GSL_SUCCESS -> smaller step and again!\n");
				varHM = oldHM;
				continue;
			} else {
				if(parHM.L() < 1024) {
					printf("          # (1) NO GSL_SUCCESS -> bigger L and again!\n");
					step1 *= 2; // I want to try with a bit bigger step, at least for a moment
					varHM = oldHM;
					parHM.set_L(1024);
					continue;
				}
				// if not, even with L=1024
				printf("          # (1) NO GSL_SUCCESS -> step too small: %f -> %e. Break the misery!\n\n", step1, step1/adapt_step_reduction);
				varHM = oldHM;
				break;
			}
		}

		// if GSL_SUCCESS==TRUE, I can print stuff
		printf("%.9f %f %f %f %f", parHM.V(), parHM.h(), coeff_H*parHM.h(), parHM.beta(), coeff_T/parHM.beta());
		rootHM.print(); printf("\n");

		// if too big jump of magnetization, we might have jumped to other phase. Then we should go back
		if(myabs(resHM.glob.magnetization-OLD_HM_m) > adapt_max_m_difference) {
			if(myabs(step1/adapt_step_reduction) >=  adapt_min_step) {
				step1 /= adapt_step_reduction;
				printf("          # (1) Big jump of magnetization %f -> %f smaller step and again!\n", OLD_HM_m, resHM.glob.magnetization);
				varHM = oldHM;
				continue;
			} else {
				if(parHM.L() < 1024) {
					printf("          # (1) Big jump of magnetization -> bigger L and again!\n");
					step1 *= 2; // I want to try with a bit bigger step, at least for a moment
					varHM = oldHM;
					parHM.set_L(1024);
					continue;
				}
				printf("          # (1) Big jump of magnetization %f -> %f and the step too small (%f -> %e). Break the misery!\n\n", OLD_HM_m, resHM.glob.magnetization, step1, step1/adapt_step_reduction);
				varHM = oldHM;
				break;
			}
		}

		// if you are here:  the new variables should be used as the new starting point
		current_x1 += step1;
		varHM.set(resHM.get_V());

		// am I too far?
		if( (step1 > 0 && current_x1 > stop1) || (step1 < 0 && current_x1 < stop1)) {
			printf("# (1) I reached the end!\n\n");
			break;
		}

		// next iteration is needed
		// decide if you should change the step in the next iteration
		int make_the_step_bigger = 0;
		int make_the_step_smaller = 0;
		double x, y;
		for(int k=0; k<3; k++) {
			//fork
			if(k==0) { x = resHM.get_V()->mu(); y = oldHM.mu(); }
			else if(k==1) { x = resHM.glob.magnetization; y = OLD_HM_m; }
			else if(k==2) { x = resHM.glob.Energy; y = OLD_HM_E; }

			if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
			else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
		}
		if(make_the_step_smaller > 0) {
			step1 /= adapt_step_reduction;
		}
		else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
			step1 *= adapt_step_reduction;
		}

		// copy new variables to OLD
		oldHM.set(resHM.get_V());
		OLD_HM_m = resHM.glob.magnetization;
		OLD_HM_E = resHM.glob.Energy;
	}
	parHM.set_V(current_x1); // the last point where I could calculate something.

	// (2) I'm pushing the PM as far as I can

	// first shoot
	varPM.shake();
	if(rootPM.Solve(varPM) != GSL_SUCCESS) { printf("# (0) First shot is not good (PM).\n"); return -1; }
	Var oldPM(*resPM.get_V());
	double OLD_PM_E = resPM.glob.Energy;
	double OLD_PM_m = resPM.glob.magnetization;

	// labels
	printf("# Belitz automatic 2 ways: pushing the PM solution (|V| decrease)\n");
	printf("# PM: "); parPM.print_verboten();
	printf("# init_varPM: "); varPM.print(); printf("\n");
	printf("# V         h        h(T)       beta       T       "); resPM.print_label(); printf("\n");
	printf("%f %f %f %f %f", parPM.V(), parPM.h(), coeff_H*parPM.h(), parPM.beta(), coeff_T/parPM.beta());
	rootPM.print(); printf("\n");
	fflush(stdout);

	int LOOPS2 = int((stop2-start2)/step2);
	if(LOOPS2 < 0) { LOOPS2 = -LOOPS2; step2 = -step2; }
	double current_x2 = start2;
	while(1) {
		fflush(stdout);
		parPM.set_V(current_x2+step2);
		varPM.shake();
		int sucessPM = rootPM.Solve(varPM);

		// if there is problem to obtain solution, take smaller step
		if(sucessPM != GSL_SUCCESS) {
			if(myabs(step2/adapt_step_reduction) >=  adapt_min_step) {
				step2 /= adapt_step_reduction;
				printf("          # (2) NO GSL_SUCCESS -> smaller step and again!\n");
				varPM = oldPM;
				continue;
			} else {
				if(parPM.L() < 1024) {
					printf("          # (2) NO GSL_SUCCESS -> bigger L and again!\n");
					step2 *= 2; // I want to try with a bit bigger step, at least for a moment
					varPM = oldPM;
					parPM.set_L(1024);
					continue;
				}
				printf("          # (2) NO GSL_SUCCESS -> step too small: %f -> %e. Break the misery!\n\n", step2, step2/adapt_step_reduction);
				varPM = oldPM;
				break;
			}
		}

		// if GSL_SUCCESS==TRUE, I can print stuff
		printf("%.9f %f %f %f %f", parPM.V(), parPM.h(), coeff_H*parPM.h(), parPM.beta(), coeff_T/parPM.beta());
		rootPM.print(); printf("\n");

		// if too big jump of magnetization, we might have jumped to other phase. Then we should go back
		if(myabs(resPM.glob.magnetization-OLD_PM_m) > adapt_max_m_difference) {
			if(myabs(step2/adapt_step_reduction) >=  adapt_min_step) {
				step2 /= adapt_step_reduction;
				printf("          # (2) Big jump of magnetization %f -> %f smaller step and again!\n", OLD_PM_m, resPM.glob.magnetization);
				varPM = oldPM;
				continue;
			} else {
				if(parPM.L() < 1024) {
					printf("          # (2) Big jump of magnetization -> bigger L and again!\n");
					step2 *= 2; // I want to try with a bit bigger step, at least for a moment
					varPM = oldHM;
					parPM.set_L(1024);
					continue;
				}
				printf("          # (2) Big jump of magnetization %f -> %f and the step too small (%f -> %e). Break the misery!\n\n", OLD_PM_m, resPM.glob.magnetization, step2, step2/adapt_step_reduction);
				break;
			}
		}

		// if you are here:  the new variables should be used as the new starting point
		current_x2 += step2;
		varPM.set(resPM.get_V());

		// am I too far?
		if( (step2 > 0 && current_x2 > stop2) || (step2 < 0 && current_x2 < stop2)) {
			printf("# (2) I reached the end!\n\n");
			break;
		}

		// next iteration is needed
		// decide if you should change the step in the next iteration
		int make_the_step_bigger = 0;
		int make_the_step_smaller = 0;
		double x, y;
		for(int k=0; k<3; k++) {
			//fork
			if(k==0) { x = resPM.get_V()->mu(); y = oldPM.mu(); }
			else if(k==1) { x = resPM.glob.magnetization; y = OLD_PM_m; }
			else if(k==2) { x = resPM.glob.Energy; y = OLD_PM_E; }

			if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
			else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
		}
		if(make_the_step_smaller > 0) {
			step2 /= adapt_step_reduction;
		}
		else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
			step2 *= adapt_step_reduction;
		}

		// copy new variables to OLD
		oldPM.set(resPM.get_V());
		OLD_PM_m = resPM.glob.magnetization;
		OLD_PM_E = resPM.glob.Energy;
	}
	parPM.set_V(current_x2); // the last point where I could calculate something.

	// sprawdzamy czy przedziały nie zachodzą lub czy nie ma przejscie II rodzaju
	if(parHM.V() > parPM.V()) {
		printf("# Przedzialy nie zachodza!\n");
		return 0;
	}
	if(sign(step1)*parHM.V() >= sign(step1)*stop1 || sign(step2)*parPM.V() >= sign(step2)*stop2) {
		printf("# Prawdopodobnie przejscie II rodzaju\n");
		return 0;
	}

	// najtrudniejszy przypadek

	//obliczam krok. Chce około 20-50 punktów, chyba że przedział jest bardzo mały
	const double start = parHM.V();
	const double stop = parPM.V();
	double step = myabs(start-stop)/20.;
	if(step < 0.000001) { step = 0.000001; }
	if(step > 0.001) { step = 0.001; }

	printf("# cofam PM do punktu startowego\n");
	parPM = parPMcp; //wracam do oryginalnego punktu
	varPM = varPMcp;
	automatic_run_V(parPM, varPM, startPM, -2.6, 0.02); printf("\n");
	automatic_run_V(parPM, varPM, -2.6, start, 0.005); printf("\n");

	// Ustalam lepszą rozdzielczosc
	parHM.set_L(1024);
	parPM.set_L(1024);

	// teraz dokładnie przeglądam przedzial
	// LABELS
	printf("#automatic_Belitz - last part\n");
	printf("#HM: "); parHM.print_verboten();
	printf("#PM: "); parPM.print_verboten();
	printf("#init_varHM: "); varHM.print(); printf("\n");
	printf("#init_varPM: "); varPM.print(); printf("\n");
	printf("# V              h        h(T)       beta       T     EHM-EPM     "); resHM.print_label(); resPM.print_label(); printf("\n");
	fflush(stdout);

	oldHM = varHM;
	oldPM = varPM;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	int isItransition = 0;
	double Vtrans = 0.;
	for(int i=0; i<=LOOPS; i++) {
		fflush(stdout);
		parHM.set_V(start + ((double)i)*step);
		parPM.set_V(start + ((double)i)*step);
		varHM.shake(); varPM.shake();
		printf("%.9f %f %f %f %f", parPM.V(), parPM.h(), coeff_H*parPM.h(), parPM.beta(), coeff_T/parPM.beta());

		int sucessHM = rootHM.Solve(varHM);
		int sucessPM = rootPM.Solve(varPM);
		if(sucessHM != GSL_SUCCESS || sucessPM != GSL_SUCCESS) {
			varHM = oldHM;
			varPM = oldPM;
			printf("\n");
			continue;
		}
		printf(" %e ", resHM.glob.Energy-resPM.glob.Energy);

		// if GSL_SUCCESS==TRUE, I can print stuff
		rootHM.print(); printf(" -2 "); rootPM.print(); printf("\n");
		fflush(stdout);
		varHM.set(resHM.get_V());
		varPM.set(resPM.get_V());

		// it will be activated only once, when HM first win
		if(isItransition == 0 && resHM.glob.Energy < resPM.glob.Energy)
		{
			isItransition = 1;
			Vtrans = start + ((double)i)*step;
			printf("# mamy przejscie I rodzaju!!! (V=(%e, %e), h=%e (%e T), T=%e (%e K)\n", Vtrans-step, Vtrans, parHM.h(), parHM.h()*coeff_H, parHM.beta(), coeff_T/parHM.beta());
		}

		// copy new variables to OLD
		oldHM.set(resHM.get_V());
		oldPM.set(resPM.get_V());
	}

	if(isItransition) {
		printf("\n# mamy przejscie I rodzaju!!! (V=(%e, %e), h=%e (%e T), T=%e (%e K)\n", Vtrans-step, Vtrans, parHM.h(), parHM.h()*coeff_H, parHM.beta(), coeff_T/parHM.beta());
	}
	else {
		printf("\n# Nie wiem jaki charakter ma to przejscie!\n");
	}


	printf("#end automatic_Belitz_2ways 2 ways\n\n");
	printf("#**********************************************************************************************************#\n");
	printf("#**********************************************************************************************************#\n");
	printf("#**********************************************************************************************************#\n\n");
	fflush(stdout);

	return 0;
}

void run_Belitz_2ways() {

	printf("start run_Belitz_2ways\n");

	for(double T=3.; T<=6.0; T+=0.3) { // in Kelwin
		automatic_Belitz_2ways(2., 2.5, T, -2.0, -3.0); // g, h
	}

	return;
}

///////////////////////////////////////////////// NOWE

int automatic_Belitz_2ways_v2(double startg, double startEpsilonF, double startT, double startHM=-2.0, double startPM=-4.0, int startL=512) {
    //////////////////////////////////////////////////////////////////////
    // wybieramy funkcję V(e_f) dla U=20 i n=1.6 (h=0) //
    //////////////////////////////////////////////////////////////////////

	printf("# start automatic_Belitz_2ways_v2: eF = %f, start HM V = %f, start PM V = %f, start T = %f, start L = %d\n", startEpsilonF, startHM, startPM, startT, startL);

	// (1) HM, h=0.01
    Par initPar_Belitz_g2h001_HM(N_PAR);
    initPar_Belitz_g2h001_HM.set_n(1.6);
    initPar_Belitz_g2h001_HM.set_t(-1.);
    initPar_Belitz_g2h001_HM.set_tPrim(0.25);
    initPar_Belitz_g2h001_HM.set_U(5.);
    initPar_Belitz_g2h001_HM.set_V(-2.0);
    initPar_Belitz_g2h001_HM.set_h(0.01);
    initPar_Belitz_g2h001_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2h001_HM.set_tF(-0.0);
    initPar_Belitz_g2h001_HM.set_gFg(2./2.);
    initPar_Belitz_g2h001_HM.set_Vint(-0.0);
    initPar_Belitz_g2h001_HM.set_alpha(0.0);
    initPar_Belitz_g2h001_HM.set_beta(5000.);
    initPar_Belitz_g2h001_HM.set_L(startL);
    //-2.000000  -1.970543060  0.657282879  0.877897786 -2.049074800  0.429965683  0.297045779 -0.085473284  0.056450889  0.000000000 -0.000000000    -5.861244735939589      0.400000000000001  0.912321254  0.885836939  0.008605632  0.123638526
    Var initV_Belitz_g2h001_HM(N_VAR);
    initV_Belitz_g2h001_HM.set_lnF(-1.970543060);
    initV_Belitz_g2h001_HM.set_lmF(0.657282879);
    initV_Belitz_g2h001_HM.set_nF(0.877897786);
    initV_Belitz_g2h001_HM.set_mu(-2.049074800);
    initV_Belitz_g2h001_HM.set_mF(0.429965683);
    initV_Belitz_g2h001_HM.set_dF(0.297045779);
    initV_Belitz_g2h001_HM.set_chiup(-0.085473284);
    initV_Belitz_g2h001_HM.set_chidown(0.056450889);
    initV_Belitz_g2h001_HM.set_lchiup(1e-12);
    initV_Belitz_g2h001_HM.set_lchidown(1e-12);

    //(2) PM, h=0.01
    Par initPar_Belitz_g2h001_PM(N_PAR);
    initPar_Belitz_g2h001_PM.set_n(1.6);
    initPar_Belitz_g2h001_PM.set_t(-1.);
    initPar_Belitz_g2h001_PM.set_tPrim(0.25);
    initPar_Belitz_g2h001_PM.set_U(5.);
    initPar_Belitz_g2h001_PM.set_V(-3.0);
    initPar_Belitz_g2h001_PM.set_h(0.01);
    initPar_Belitz_g2h001_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2h001_PM.set_tF(-0.0);
    initPar_Belitz_g2h001_PM.set_gFg(2./2.);
    initPar_Belitz_g2h001_PM.set_Vint(-0.0);
    initPar_Belitz_g2h001_PM.set_alpha(0.0);
    initPar_Belitz_g2h001_PM.set_beta(5000.);
    initPar_Belitz_g2h001_PM.set_L(startL);
    //-3.000000  -1.900647644  0.035014344  0.832477123 -2.862847429  0.020821503  0.340072775  0.040879598  0.047596211  0.000000000 -0.000000000    -7.322624984355449      0.022313523402390  0.941678714  0.940835070  0.009438461  0.012752674
    Var initV_Belitz_g2h001_PM(N_VAR);
    initV_Belitz_g2h001_PM.set_lnF(-1.900647644);
    initV_Belitz_g2h001_PM.set_lmF(0.035014344);
    initV_Belitz_g2h001_PM.set_nF(0.832477123);
    initV_Belitz_g2h001_PM.set_mu(-2.862847429);
    initV_Belitz_g2h001_PM.set_mF(0.020821503);
    initV_Belitz_g2h001_PM.set_dF(0.340072775);
    initV_Belitz_g2h001_PM.set_chiup(0.040879598);
    initV_Belitz_g2h001_PM.set_chidown(0.047596211);
    initV_Belitz_g2h001_PM.set_lchiup(1e-12);
    initV_Belitz_g2h001_PM.set_lchidown(1e-12);

    // NOwE

	// (1) HM, h=0.0
    Par initPar_Belitz_g2h0_HM(N_PAR);
    initPar_Belitz_g2h0_HM.set_n(1.6);
    initPar_Belitz_g2h0_HM.set_t(-1.);
    initPar_Belitz_g2h0_HM.set_tPrim(0.25);
    initPar_Belitz_g2h0_HM.set_U(20.);
    initPar_Belitz_g2h0_HM.set_V(-2.0);
    initPar_Belitz_g2h0_HM.set_h(0.0);
    initPar_Belitz_g2h0_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2h0_HM.set_tF(-0.0);
    initPar_Belitz_g2h0_HM.set_gFg(2./2.);
    initPar_Belitz_g2h0_HM.set_Vint(-0.0);
    initPar_Belitz_g2h0_HM.set_alpha(0.0);
    initPar_Belitz_g2h0_HM.set_beta(5000.);
    initPar_Belitz_g2h0_HM.set_L(startL);
    //20.000000  -2.661029747  0.908185733  0.755647290 -1.169999984  0.477540947  0.088678597 -0.096984699  0.031550076  0.000000000  0.000000000    -5.442908800914806      0.399999999999994  0.760278863  0.526622897  0.212491853  1.095975325
    Var initV_Belitz_g2h0_HM(N_VAR);
    initV_Belitz_g2h0_HM.set_lnF(-2.661029747);
    initV_Belitz_g2h0_HM.set_lmF(0.908185733);
    initV_Belitz_g2h0_HM.set_nF(0.755647290);
    initV_Belitz_g2h0_HM.set_mu(-1.169999984);
    initV_Belitz_g2h0_HM.set_mF(0.477540947);
    initV_Belitz_g2h0_HM.set_dF(0.088678597);
    initV_Belitz_g2h0_HM.set_chiup(-0.096984699);
    initV_Belitz_g2h0_HM.set_chidown(0.031550076);
    initV_Belitz_g2h0_HM.set_lchiup(1e-12);
    initV_Belitz_g2h0_HM.set_lchidown(1e-12);

    //(2) PM, h=0.0
    Par initPar_Belitz_g2h0_PM(N_PAR);
    initPar_Belitz_g2h0_PM.set_n(1.6);
    initPar_Belitz_g2h0_PM.set_t(-1.);
    initPar_Belitz_g2h0_PM.set_tPrim(0.25);
    initPar_Belitz_g2h0_PM.set_U(20.);
    initPar_Belitz_g2h0_PM.set_V(-5.0);
    initPar_Belitz_g2h0_PM.set_h(0.0);
    initPar_Belitz_g2h0_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2h0_PM.set_tF(-0.0);
    initPar_Belitz_g2h0_PM.set_gFg(2./2.);
    initPar_Belitz_g2h0_PM.set_Vint(-0.0);
    initPar_Belitz_g2h0_PM.set_alpha(0.0);
    initPar_Belitz_g2h0_PM.set_beta(5000.);
    initPar_Belitz_g2h0_PM.set_L(startL);
    //-5.000000  -3.985784527  0.000000000  0.648316007 -3.172575165  0.000000000  0.179422432  0.039408528  0.039408528 -0.000000000 -0.000000000    -9.410675856425282      0.000000000000365  0.850791899  0.850791899  0.175845737  0.175845737
    Var initV_Belitz_g2h0_PM(N_VAR);
    initV_Belitz_g2h0_PM.set_lnF(-3.985784527);
    initV_Belitz_g2h0_PM.set_lmF(1e-12);
    initV_Belitz_g2h0_PM.set_nF(0.648316007);
    initV_Belitz_g2h0_PM.set_mu(-3.172575165);
    initV_Belitz_g2h0_PM.set_mF(1e-12);
    initV_Belitz_g2h0_PM.set_dF(0.179422432);
    initV_Belitz_g2h0_PM.set_chiup(0.039408528);
    initV_Belitz_g2h0_PM.set_chidown(0.039408528);
    initV_Belitz_g2h0_PM.set_lchiup(1e-12);
    initV_Belitz_g2h0_PM.set_lchidown(1e-12);

	// I'm choosing start points
    Par parHM = initPar_Belitz_g2h0_HM;
	Var varHM = initV_Belitz_g2h0_HM;
	Par parPM = initPar_Belitz_g2h0_PM;
	Var varPM = initV_Belitz_g2h0_PM;

	Res resHM(N_VAR);
	RootGSL rootHM(parHM, function, resHM);
	Res resPM(N_VAR);
	RootGSL rootPM(parPM, function, resPM);

	// *********************************************************************************** //
	// ********************** Going to the starting point ******************************** //
	// *********************************************************************************** //

	printf("#dochodze do punktu startowego\n");

	varHM.shake(); varPM.shake();
	automatic_run_T(parHM, varHM, 1./500., startT, 0.001);
	automatic_run_T(parPM, varPM, 1./500., startT, 0.001);

//	varHM.shake(); varPM.shake();
//	automatic_run_gFg(parHM, varHM, 2./2., startg/2., 0.02);
//	automatic_run_gFg(parPM, varPM, 2./2., startg/2., 0.02);
	if(startg != 2.) { printf("#ERROR: g must be 2.\n"); return 0; }

	varHM.shake(); varPM.shake();
	automatic_run_V(parHM, varHM, -2., startHM, 0.1);
	automatic_run_V(parPM, varPM, -5, startPM, 0.1);

	varHM.shake(); varPM.shake();
	automatic_run_epsilonF(parHM, varHM, -3.0, startEpsilonF, 0.1);
	automatic_run_epsilonF(parPM, varPM, -3.0, startEpsilonF, 0.1);

	//robie kobie PM
	Par parPMcp = parPM;
	Var varPMcp = varPM;

	printf("#Jestem w punkcie startowym\n");

	// PARAMETERS
	const double start1 = startHM;
	const double stop1 = startPM; // maximum
	double step1 = 0.01;

//	const double start2 = startPM;
//	const double stop2 = startHM; // maximum
//	double step2 = 0.01;

	// *********************************************************************************** //
	// *********************************************************************************** //

	// (1) I'm pushing the HM as far as I can

	// first shoot
	varHM.shake();
	if(rootHM.Solve(varHM) != GSL_SUCCESS) { printf("# (0) First shot is not good (HM).\n"); return -1; }
	Var oldHM(*resHM.get_V());
	double OLD_HM_E = resHM.glob.Energy;
	double OLD_HM_m = resHM.glob.magnetization;

	// labels
	printf("# Belitz automatic 2 ways: pushing the HM solution (|V| increase)\n");
	printf("# HM: "); parHM.print_verboten();
	printf("# init_varHM: "); varHM.print(); printf("\n");
	printf("# V            h        eF        beta       1/beta  "); resHM.print_label(); printf("\n");
	printf("%.9f %f %f %f %f", parHM.V(), parHM.h(), parHM.epsilonF(), parHM.beta(), 1./parHM.beta());
	rootHM.print(); printf("\n");

	// run
	int LOOPS1 = int((stop1-start1)/step1);
	if(LOOPS1 < 0) { LOOPS1 = -LOOPS1; step1 = -step1; }
	double current_x1 = start1;
	while(1) {
		fflush(stdout);
		parHM.set_V(current_x1+step1);
		varHM.shake();
		int sucessHM = rootHM.Solve(varHM);

		// if there is problem to obtain solution, take smaller step
		if(sucessHM != GSL_SUCCESS) {
			if(myabs(step1/adapt_step_reduction) >=  adapt_min_step) {
				step1 /= adapt_step_reduction;
				printf("          # (1) NO GSL_SUCCESS -> smaller step and again!\n");
				varHM = oldHM;
				continue;
			} else {
				if(parHM.L() < 1024) {
					printf("          # (1) NO GSL_SUCCESS -> bigger L and again!\n");
					step1 *= 2; // I want to try with a bit bigger step, at least for a moment
					varHM = oldHM;
					parHM.set_L(1024);
					continue;
				}
				// if not, even with L=1024
				printf("          # (1) NO GSL_SUCCESS -> step too small: %f -> %e. Break the misery!\n\n", step1, step1/adapt_step_reduction);
				varHM = oldHM;
				break;
			}
		}

		// if GSL_SUCCESS==TRUE, I can print stuff
		printf("%.9f %f %f %f %f", parHM.V(), parHM.h(), parHM.epsilonF(), parHM.beta(), 1./parHM.beta());
		rootHM.print(); printf("\n");

		// if too big jump of magnetization, we might have jumped to other phase. Then we should go back
		if(myabs(resHM.glob.magnetization-OLD_HM_m) > adapt_max_m_difference) {
			if(myabs(step1/adapt_step_reduction) >=  adapt_min_step) {
				step1 /= adapt_step_reduction;
				printf("          # (1) Big jump of magnetization %f -> %f smaller step and again!\n", OLD_HM_m, resHM.glob.magnetization);
				varHM = oldHM;
				continue;
			} else {
				if(parHM.L() < 1024) {
					printf("          # (1) Big jump of magnetization -> bigger L and again!\n");
					step1 *= 2; // I want to try with a bit bigger step, at least for a moment
					varHM = oldHM;
					parHM.set_L(1024);
					continue;
				}
				printf("          # (1) Big jump of magnetization %f -> %f and the step too small (%f -> %e). Break the misery!\n\n", OLD_HM_m, resHM.glob.magnetization, step1, step1/adapt_step_reduction);
				varHM = oldHM;
				break;
			}
		}

		// if you are here:  the new variables should be used as the new starting point
		current_x1 += step1;
		varHM.set(resHM.get_V());

		// am I too far?
		if( (step1 > 0 && current_x1 > stop1) || (step1 < 0 && current_x1 < stop1)) {
			printf("# (1) I reached the end!\n\n");
			break;
		}

		// next iteration is needed
		// decide if you should change the step in the next iteration
		int make_the_step_bigger = 0;
		int make_the_step_smaller = 0;
		double x, y;
		for(int k=0; k<3; k++) {
			//fork
			if(k==0) { x = resHM.get_V()->mu(); y = oldHM.mu(); }
			else if(k==1) { x = resHM.glob.magnetization; y = OLD_HM_m; }
			else if(k==2) { x = resHM.glob.Energy; y = OLD_HM_E; }

			if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
			else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
		}
		if(make_the_step_smaller > 0) {
			step1 /= adapt_step_reduction;
		}
		else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
			step1 *= adapt_step_reduction;
		}

		// copy new variables to OLD
		oldHM.set(resHM.get_V());
		OLD_HM_m = resHM.glob.magnetization;
		OLD_HM_E = resHM.glob.Energy;
	}
	parHM.set_V(current_x1); // the last point where I could calculate something.

	// (2) I'm pushing the PM as far as I can

	// first shoot
	varPM.shake();
	if(rootPM.Solve(varPM) != GSL_SUCCESS) { printf("# (0) First shot is not good (PM).\n"); return -1; }
	Var oldPM(*resPM.get_V());
/*	double OLD_PM_E = resPM.glob.Energy;
	double OLD_PM_m = resPM.glob.magnetization;

	// labels
	printf("# Belitz automatic 2 ways: pushing the PM solution (|V| decrease)\n");
	printf("# PM: "); parPM.print_verboten();
	printf("# init_varPM: "); varPM.print(); printf("\n");
	printf("# V         h        h(T)       beta       T       "); resPM.print_label(); printf("\n");
	printf("%f %f %f %f %f", parPM.V(), parPM.h(), coeff_H*parPM.h(), parPM.beta(), coeff_T/parPM.beta());
	rootPM.print(); printf("\n");
	fflush(stdout);

	int LOOPS2 = int((stop2-start2)/step2);
	if(LOOPS2 < 0) { LOOPS2 = -LOOPS2; step2 = -step2; }
	double current_x2 = start2;
	while(1) {
		fflush(stdout);
		parPM.set_V(current_x2+step2);
		varPM.shake();
		int sucessPM = rootPM.Solve(varPM);

		// if there is problem to obtain solution, take smaller step
		if(sucessPM != GSL_SUCCESS) {
			if(myabs(step2/adapt_step_reduction) >=  adapt_min_step) {
				step2 /= adapt_step_reduction;
				printf("          # (2) NO GSL_SUCCESS -> smaller step and again!\n");
				varPM = oldPM;
				continue;
			} else {
				if(parPM.L() < 1024) {
					printf("          # (2) NO GSL_SUCCESS -> bigger L and again!\n");
					step2 *= 2; // I want to try with a bit bigger step, at least for a moment
					varPM = oldPM;
					parPM.set_L(1024);
					continue;
				}
				printf("          # (2) NO GSL_SUCCESS -> step too small: %f -> %e. Break the misery!\n\n", step2, step2/adapt_step_reduction);
				varPM = oldPM;
				break;
			}
		}

		// if GSL_SUCCESS==TRUE, I can print stuff
		printf("%.9f %f %f %f %f", parPM.V(), parPM.h(), coeff_H*parPM.h(), parPM.beta(), coeff_T/parPM.beta());
		rootPM.print(); printf("\n");

		// if too big jump of magnetization, we might have jumped to other phase. Then we should go back
		if(myabs(resPM.glob.magnetization-OLD_PM_m) > adapt_max_m_difference) {
			if(myabs(step2/adapt_step_reduction) >=  adapt_min_step) {
				step2 /= adapt_step_reduction;
				printf("          # (2) Big jump of magnetization %f -> %f smaller step and again!\n", OLD_PM_m, resPM.glob.magnetization);
				varPM = oldPM;
				continue;
			} else {
				if(parPM.L() < 1024) {
					printf("          # (2) Big jump of magnetization -> bigger L and again!\n");
					step2 *= 2; // I want to try with a bit bigger step, at least for a moment
					varPM = oldHM;
					parPM.set_L(1024);
					continue;
				}
				printf("          # (2) Big jump of magnetization %f -> %f and the step too small (%f -> %e). Break the misery!\n\n", OLD_PM_m, resPM.glob.magnetization, step2, step2/adapt_step_reduction);
				break;
			}
		}

		// if you are here:  the new variables should be used as the new starting point
		current_x2 += step2;
		varPM.set(resPM.get_V());

		// am I too far?
		if( (step2 > 0 && current_x2 > stop2) || (step2 < 0 && current_x2 < stop2)) {
			printf("# (2) I reached the end!\n\n");
			break;
		}

		// next iteration is needed
		// decide if you should change the step in the next iteration
		int make_the_step_bigger = 0;
		int make_the_step_smaller = 0;
		double x, y;
		for(int k=0; k<3; k++) {
			//fork
			if(k==0) { x = resPM.get_V()->mu(); y = oldPM.mu(); }
			else if(k==1) { x = resPM.glob.magnetization; y = OLD_PM_m; }
			else if(k==2) { x = resPM.glob.Energy; y = OLD_PM_E; }

			if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
			else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
		}
		if(make_the_step_smaller > 0) {
			step2 /= adapt_step_reduction;
		}
		else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
			step2 *= adapt_step_reduction;
		}

		// copy new variables to OLD
		oldPM.set(resPM.get_V());
		OLD_PM_m = resPM.glob.magnetization;
		OLD_PM_E = resPM.glob.Energy;
	}
	parPM.set_V(current_x2); // the last point where I could calculate something.

	// sprawdzamy czy przedziały nie zachodzą lub czy nie ma przejscie II rodzaju
	if(parHM.V() > parPM.V()) {
		printf("# Przedzialy nie zachodza!\n");
		return 0;
	}
*/	//if(sign(step1)*parHM.V() >= sign(step1)*stop1 || sign(step2)*parPM.V() >= sign(step2)*stop2) {
	if(sign(step1)*parHM.V() >= sign(step1)*stop1) {
		printf("# Prawdopodobnie przejscie II rodzaju\n");
		return 0;
	}

	// najtrudniejszy przypadek

	//obliczam krok. Chce około 20-50 punktów, chyba że przedział jest bardzo mały
	const double start = parHM.V();
	const double stop = parHM.V()+0.6; //parPM.V(); // stare
	double step = myabs(start-stop)/100.;
	if(step < 0.000001) { step = 0.000001; }
	if(step > 0.002) { step = 0.0002; }

	printf("# cofam PM do punktu startowego\n");
	parPM = parPMcp; //wracam do oryginalnego punktu
	varPM = varPMcp;
	automatic_run_V(parPM, varPM, startPM, start, 0.01); printf("\n");

	// Ustalam lepszą rozdzielczosc
	parHM.set_L(1024);
	parPM.set_L(1024);

	// teraz dokładnie przeglądam przedzial
	// LABELS
	printf("#automatic_Belitz - last part\n");
	printf("#HM: "); parHM.print_verboten();
	printf("#PM: "); parPM.print_verboten();
	printf("#init_varHM: "); varHM.print(); printf("\n");
	printf("#init_varPM: "); varPM.print(); printf("\n");
	printf("# V              h        e_f        beta       T     EHM-EPM     "); resHM.print_label(); resPM.print_label(); printf("\n");
	fflush(stdout);

	oldHM = varHM;
	oldPM = varPM;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	int isItransition = 0;
	int breakFast = 0;
	double Vtrans = 0.;
	for(int i=0; i<=LOOPS; i++) {
		fflush(stdout);
		parHM.set_V(start + ((double)i)*step);
		parPM.set_V(start + ((double)i)*step);
		varHM.shake(); varPM.shake();
		printf("%.9f %f %f %f %f", parPM.V(), parPM.h(), parPM.epsilonF(), parPM.beta(), coeff_T/parPM.beta());

		int sucessHM = rootHM.Solve(varHM);
		int sucessPM = rootPM.Solve(varPM);
		if(sucessHM != GSL_SUCCESS || sucessPM != GSL_SUCCESS) {
			varHM = oldHM;
			varPM = oldPM;
			printf("\n");
			continue;
		}
		printf(" %e ", resHM.glob.Energy-resPM.glob.Energy);

		// if GSL_SUCCESS==TRUE, I can print stuff
		rootHM.print(); printf(" -2 "); rootPM.print(); printf("\n");
		fflush(stdout);
		varHM.set(resHM.get_V());
		varPM.set(resPM.get_V());

		// it will be activated only once, when HM first win
		if(isItransition == 0 && resHM.glob.Energy < resPM.glob.Energy)
		{
			isItransition = 1;
			Vtrans = start + ((double)i)*step;
			printf("# mamy przejscie I rodzaju!!! V=(%e, %e), h=%e, e_f=%e, beta=%e, T=%e\n", Vtrans-step, Vtrans, parHM.h(), parHM.epsilonF(), parHM.beta(), coeff_T/parHM.beta());
		}

		// zeby skrocic
		//(1)
		// break after 5
		if(isItransition > 0 || resHM.glob.Energy<resPM.glob.Energy) {
			breakFast++;
			if(breakFast>5) { break; }
		}


		// copy new variables to OLD
		oldHM.set(resHM.get_V());
		oldPM.set(resPM.get_V());
	}

	if(isItransition) {
		printf("\n# mamy przejscie I rodzaju!!! (V=(%e, %e), h=%e (%e T), T=%e (%e K)\n", Vtrans-step, Vtrans, parHM.h(), parHM.h()*coeff_H, parHM.beta(), coeff_T/parHM.beta());
	}
	else {
		printf("\n# Nie wiem jaki charakter ma to przejscie!\n");
	}


	printf("#end automatic_Belitz_2ways 2 ways\n\n");
	printf("#**********************************************************************************************************#\n");
	printf("#**********************************************************************************************************#\n");
	printf("#**********************************************************************************************************#\n\n");
	fflush(stdout);

	return 0;
}

void run_Belitz_2ways_v2() {

	printf("start run_Belitz_2ways\n");

	for(double T=0.01; T<=0.20; T+=0.005) { // in Kelwin
		automatic_Belitz_2ways_v2(2., -1.95, T, -2.0, -2.5); // g, h
	}

	return;
}

///////////////////////////////////////////////// NOWE koniec

void run_Belitz_automatic2D() {

    //////////////////////////////////////////////////////////////////////
    // (B) badamy wplyw tF i h na magnetyzacje dla U=5 i n=1.8 (h=0) //
    //////////////////////////////////////////////////////////////////////

	// (1) HM, h=0
    Par initPar_Belitz_g2_HM(N_PAR);
    initPar_Belitz_g2_HM.set_n(1.6);
    initPar_Belitz_g2_HM.set_t(-1.);
    initPar_Belitz_g2_HM.set_tPrim(0.25);
    initPar_Belitz_g2_HM.set_U(5.);
    initPar_Belitz_g2_HM.set_V(-2.0);
    initPar_Belitz_g2_HM.set_h(0.0);
    initPar_Belitz_g2_HM.set_epsilonF(-3.0);
    initPar_Belitz_g2_HM.set_tF(-0.0);
    initPar_Belitz_g2_HM.set_gFg(2./2.);
    initPar_Belitz_g2_HM.set_Vint(-0.0);
    initPar_Belitz_g2_HM.set_alpha(0.0);
    initPar_Belitz_g2_HM.set_beta(5000.);
    initPar_Belitz_g2_HM.set_L(512);
    //-2.000000  -1.970540748  0.657285840  0.877897261 -2.059200477  0.429967158  0.297045327 -0.085473185  0.056446699  0.000000000  0.000000000    -5.857241236298249      0.399999999999973  0.912321747  0.885837291  0.008605689  0.123639248
    Var initV_Belitz_g2_HM(N_VAR);
    initV_Belitz_g2_HM.set_lnF(-1.970540748);
    initV_Belitz_g2_HM.set_lmF(0.657285840);
    initV_Belitz_g2_HM.set_nF(0.877897261);
    initV_Belitz_g2_HM.set_mu(-2.059200477);
    initV_Belitz_g2_HM.set_mF(0.429967158);
    initV_Belitz_g2_HM.set_dF(0.297045327);
    initV_Belitz_g2_HM.set_chiup(-0.085473185);
    initV_Belitz_g2_HM.set_chidown(0.056446699);
    initV_Belitz_g2_HM.set_lchiup(1e-12);
    initV_Belitz_g2_HM.set_lchidown(1e-12);


    //(2) PM, h=0
    Par initPar_Belitz_g2_PM(N_PAR);
    initPar_Belitz_g2_PM.set_n(1.6);
    initPar_Belitz_g2_PM.set_t(-1.);
    initPar_Belitz_g2_PM.set_tPrim(0.25);
    initPar_Belitz_g2_PM.set_U(5.);
    initPar_Belitz_g2_PM.set_V(-2.0);
    initPar_Belitz_g2_PM.set_h(0.0);
    initPar_Belitz_g2_PM.set_epsilonF(-3.0);
    initPar_Belitz_g2_PM.set_tF(-0.0);
    initPar_Belitz_g2_PM.set_gFg(2./2.);
    initPar_Belitz_g2_PM.set_Vint(-0.0);
    initPar_Belitz_g2_PM.set_alpha(0.0);
    initPar_Belitz_g2_PM.set_beta(5000.);
    initPar_Belitz_g2_PM.set_L(512);
    //-2.000000  -1.862453523  0.000000000  0.852036257 -2.017313801  0.000000000  0.309279281  0.032097262  0.032097262 -0.000000000  0.000000000    -5.844957750254139      0.000000000000030  0.870846795  0.870846795  0.024237170  0.024237170
    Var initV_Belitz_g2_PM(N_VAR);
    initV_Belitz_g2_PM.set_lnF(-1.862453523);
    initV_Belitz_g2_PM.set_lmF(1e-12);
    initV_Belitz_g2_PM.set_nF(0.852036257);
    initV_Belitz_g2_PM.set_mu(-2.017313801);
    initV_Belitz_g2_PM.set_mF(1e-12);
    initV_Belitz_g2_PM.set_dF(0.309279281);
    initV_Belitz_g2_PM.set_chiup(0.0320972625);
    initV_Belitz_g2_PM.set_chidown(0.032097262);
    initV_Belitz_g2_PM.set_lchiup(1e-12);
    initV_Belitz_g2_PM.set_lchidown(1e-12);


	// I'm choosing start point
	Par parHM = initPar_Belitz_g2_HM;
	Var varHM = initV_Belitz_g2_HM;
	Par parPM = initPar_Belitz_g2_PM;
	Var varPM = initV_Belitz_g2_PM;

	// PARAMETERS
	const double start_x = -2.0;
	const double stop_x = -2.6;
	double step_x = 0.01;

	// temperature
	const double start_y = 0.5;
	const double stop_y = 50;
	double step_y = 0.5;

	// First shoot
	Res resHM(N_VAR);
	RootGSL rootHM(parHM, function, resHM);
	if(rootHM.Solve(varHM) != GSL_SUCCESS) { printf("First shot is not good (HM).\n"); return; }
	Var oldHM(*resHM.get_V());
	double OLD_HM_E = resHM.glob.Energy;
	double OLD_HM_m = resHM.glob.magnetization;

	Res resPM(N_VAR);
	RootGSL rootPM(parPM, function, resPM);
	if(rootPM.Solve(varPM) != GSL_SUCCESS) { printf("First shot is not good (PM).\n"); return; }
	Var oldPM(*resPM.get_V());
	double OLD_PM_E = resPM.glob.Energy;
	double OLD_PM_m = resPM.glob.magnetization;

	// LABELS
	printf("#automatic_Belitz\n");
	printf("#HM: "); parHM.print_verboten();
	printf("#PM: "); parPM.print_verboten();
	printf("#init_varHM: "); varHM.print(); printf("\n");
	printf("#init_varPM: "); varPM.print(); printf("\n");
	printf("#T           beta        V         step      "); resHM.print_label(); resPM.print_label(); printf("\n");
	fflush(stdout);

	// RUN (y)
	int LOOPS_y = int((stop_y-start_y)/step_y);
	if(LOOPS_y < 0) { LOOPS_y = -LOOPS_y; step_y = -step_y; }
	for(int i=0; i<LOOPS_y; i++) {
		double current_y = start_y + ((double)i)*step_y;
		double current_beta = coeff_T/current_y;
		parHM.set_beta(current_beta);
		parPM.set_beta(current_beta);


		// RUN (x)
		varHM = oldHM;
		varPM = oldPM;
		int LOOPS_x = int((stop_x-start_x)/step_x);
		if(LOOPS_x < 0) { LOOPS_x = -LOOPS_x; step_x = -step_x; }
		double current_x = start_x;
		while(1) {
			parHM.set_V(current_x);
			parPM.set_V(current_x);
			varHM.shake(); varPM.shake();

			int sucessHM = rootHM.Solve(varHM);
			double HM_E = resHM.glob.Energy;
			double HM_m = resHM.glob.magnetization;
			int sucessPM = rootPM.Solve(varPM);
			double PM_E = resPM.glob.Energy;
			double PM_m = resPM.glob.magnetization;

			// if there is problem to obtain solution, take smaller step
			if(sucessHM != GSL_SUCCESS || sucessPM != GSL_SUCCESS) {
				if(myabs(step_x/adapt_step_reduction) >=  adapt_min_step) {
					step_x /= adapt_step_reduction;
					printf("#NO GSL_SUCCESS -> smaller step and again! (HM=%d, PM=%d, SUCESS=%d).\n", sucessHM, sucessPM, GSL_SUCCESS);
					continue;
				} else {
					printf("#NO GSL_SUCCESS -> step too small (%f, %e). Break the misery!\n\n", step_x, step_x/adapt_step_reduction);
					break;
				}
			}

			// if too big jump of magnetization, we might jump to other phase
			if(myabs(HM_m-OLD_HM_m) > adapt_max_m_difference) {
				if(myabs(step_x/adapt_step_reduction) >=  adapt_min_step) {
					step_x /= adapt_step_reduction;
					printf("#Big jump of magnetization -> smaller step and again! ");
					rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
					continue;
				} else {
					printf("#Big jump of magnetization and the step too small (%f, %e). Break the misery!\n\n", step_x, step_x/adapt_step_reduction);
					break;
				}
			}

			// special case, if PM starts winning
			if(PM_E < HM_E && myabs(PM_m - HM_m) > adapt_min_m_difference) {
				if(myabs(step_x/adapt_step_reduction) >=  adapt_min_step) {
					step_x /= adapt_step_reduction;
					printf("#PM_E < HM_E -> smaller step! n=%f V=%f eF=%f step=%f: ", parHM.n(), parHM.V(), parHM.epsilonF(), step_x);
					rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
					continue;
				} else {
					printf("#"); rootHM.print(); printf(" <HM|PM>  "); rootPM.print(); printf("\n"); fflush(stdout);
					printf("#PM_E < HM_E -> I got I order transition between HM and PM\n");
					printf("#V in (%f, %f)\n\n", current_x, current_x + step_x);
					break;
				}
			}
			// special case, when HM jumped to PM
			if(myabs(PM_m - HM_m) < adapt_min_m_difference) { // we do have jump or II order transition
				if(myabs(step_x/adapt_step_reduction) >=  adapt_min_step) {
					step_x /= adapt_step_reduction;
					printf("#PM_m = HM_m -> smaller step! n=%f V=%f eF=%f step=%f: ", parHM.n(), parHM.V(), parHM.epsilonF(), step_x);
					printf("PM: E=%e, m=%e | HM: E=%e, m=%e, E_PM-E_HM=%e", resPM.glob.Energy, resPM.glob.magnetization, resHM.glob.Energy, resHM.glob.magnetization, resPM.glob.Energy-resHM.glob.magnetization);
					rootPM.print(); printf(" <PM|HM>  "); rootHM.print(); printf("\n"); fflush(stdout);
					continue;
				} else {
					printf("#");
					rootPM.print(); printf(" <PM|HM>  "); rootHM.print(); printf("\n"); fflush(stdout);
					printf("#PM_m = HM_m -> I got II order transition or jump between HM and PM\n");
					printf("#T=%f, beta=%e, V in (%f, %f)\n\n", current_y, current_beta, current_x, current_x + step_x);
					break;
				}
			}

			// if you are here, it works, you can print stuff and as a starting point use the new variables
			current_x += step_x;
			printf("%f %f %f  %f ", current_y, parHM.beta(), parHM.V(), step_x);
			rootHM.print();
			printf(" -2  ");
			rootPM.print(); printf("\n"); fflush(stdout);
			varHM.set(resHM.get_V());
			varPM.set(resPM.get_V());

			// decide if you should change the step
			int make_the_step_bigger = 0;
			int make_the_step_smaller = 0;
			double x, y;
			for(int k=0; k<6; k++) {
				//fork
				if(k==0) { x = resPM.get_V()->mu(); y = oldPM.mu(); }
				else if(k==1) { x = resHM.get_V()->mu(); y = oldHM.mu(); }
				else if(k==2) { x = PM_m; y = OLD_PM_m; }
				else if(k==3) { x = HM_m; y = OLD_HM_m; }
				else if(k==4) { x = PM_E; y = OLD_PM_E; }
				else if(k==5) { x = HM_E; y = OLD_HM_E; }

				if( myabs(x-y) < adapt_min_difference) { make_the_step_bigger++; }
				else if( myabs(x-y) > adapt_max_difference) { make_the_step_smaller++; }
			}

			if(make_the_step_smaller > 0) {
				step_x /= adapt_step_reduction;
			}
			else if(make_the_step_smaller == 0 && make_the_step_bigger > 0) {
				step_x *= adapt_step_reduction;
			}

			// am I too far?
			if( (step_x > 0 && current_x > stop_x) || (step_x < 0 && current_x < stop_x)) {
				printf("#I'm too far\n");
				break;
			}

			// if here, it means we are going around again
			current_x += step_x;
			// copy new variables to OLD
			oldHM.set(resHM.get_V());
			OLD_HM_m = HM_m;
			OLD_HM_E = HM_E;
			oldPM.set(resPM.get_V());
			OLD_PM_m = PM_m;
			OLD_PM_E = PM_E;
		}

	}
	printf("#end automatic_run_Belitz_automatic\n\n\n");
	fflush(stdout);

	return;
}

/////////////////////////////////////////////////////////////////////////
///*******************************************************************///
/////////////////////////////////////////////////////////////////////////

void automatic_run_n(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_n, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#n           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_n(start + ((double)i)*step);
		printf("%f ", inpar.n());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	inpar.set_n(stop);
	invar = initV;

	printf("#end automatic_run_n\n\n\n");
	fflush(stdout);
	return;
}

void automatic_run_tPrim(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_tPrim, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#tPrim       "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_tPrim(start + ((double)i)*step);
		printf("%f ", inpar.tPrim());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_tPrim\n\n\n");
	fflush(stdout);

	inpar.set_tPrim(stop);
	invar = initV;
	return;
}

void automatic_run_U(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_U, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#U           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_U(start + ((double)i)*step);
		printf("%f ", inpar.U());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_U\n\n\n");
	fflush(stdout);

	inpar.set_U(stop);
	invar = initV;
	return;
}

void automatic_run_V(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_V, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#V           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_V(start + ((double)i)*step);
		printf("%f ", inpar.V());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_V\n\n\n");
	fflush(stdout);

	inpar.set_V(stop);
	invar = initV;
	return;
}

void automatic_run_h(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_h, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_h(start + ((double)i)*step);
		printf("%f ", inpar.h());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_h\n\n\n");
	fflush(stdout);

	inpar.set_h(stop);
	invar = initV;
	return;
}

void automatic_run_epsilonF(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_epsilonF, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#epsilonF    "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_epsilonF(start + ((double)i)*step);
		printf("%f ", inpar.epsilonF());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_epsilonF\n\n\n");
	fflush(stdout);

	inpar.set_epsilonF(stop);
	invar = initV;
	return;
}

void automatic_run_beta(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_beta, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#beta        "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_beta(start + ((double)i)*step);
		printf("%f ", inpar.beta());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_beta\n\n\n");
	fflush(stdout);

	inpar.set_beta(stop);
	invar = initV;
	return;
}

void automatic_run_T(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_T, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#T          beta       "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_beta(coeff_T/(start + ((double)i)*step));
		printf("%10f %10f", coeff_T/inpar.beta(), inpar.beta());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_beta\n\n\n");
	fflush(stdout);

	inpar.set_beta(coeff_T/stop);
	invar = initV;
	return;
}

void automatic_run_L(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_L, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#L           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_L(start + ((double)i)*step);
		printf("%d ", inpar.L());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_L\n\n\n");
	fflush(stdout);

	inpar.set_L(stop);
	invar = initV;
	return;
}

void automatic_run_tF(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_tF, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#tF           "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_tF(start + ((double)i)*step);
		printf("%f ", inpar.tF());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_tF\n\n\n");
	fflush(stdout);

	inpar.set_tF(stop);
	invar = initV;
	return;
}

void automatic_run_Vint(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_Vint, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#Vint       "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_Vint(start + ((double)i)*step);
		printf("%f ", inpar.Vint());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_Vint\n\n\n");
	fflush(stdout);

	inpar.set_Vint(stop);
	invar = initV;
	return;
}

void automatic_run_gFg(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_gFg, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#gFg        "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_gFg(start + ((double)i)*step);
		printf("%f ", inpar.gFg());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_gFg\n\n\n");
	fflush(stdout);

	inpar.set_gFg(stop);
	invar = initV;
	return;
}



void automatic_2Drun_VintV(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_Vint(start1);
	par.set_V(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#Vint      V            "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_Vint(start1 + ((double)i)*step1);
		par.set_V(start2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_V(start2 + ((double)j)*step2);
			printf("%f %f   ", par.Vint(), par.V());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_Vint(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}



void automatic_2Drun_VVint(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_V(start1);
	par.set_Vint(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#Vint          V         "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_V(start1 + ((double)i)*step1);
		par.set_Vint(start2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_Vint(start2 + ((double)j)*step2);
			printf("%f %f   ", par.Vint(), par.V());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_V(stop1); par.set_Vint(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_hV(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_h(start1);
	par.set_V(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h          V            "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_h(start1 + ((double)i)*step1);
		par.set_V(start2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_V(start2 + ((double)j)*step2);
			printf("%f %f   ", par.h(), par.V());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_h(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_hVtF(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2, double tFstart, double tFstop, double tFvalue) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_h(start1);
	par.set_V(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h          V            tF             "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_h(start1 + ((double)i)*step1);
		par.set_V(start2);

			if(par.V() > tFstart){ par.set_tF(0); }
			else if(par.V() > tFstop){ par.set_tF(abs(par.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
			else { par.set_tF(tFvalue); }

		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_V(start2 + ((double)j)*step2);

			if(par.V() > tFstart){ par.set_tF(0); }
			else if(par.V() > tFstop){ par.set_tF(abs(par.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
			else { par.set_tF(tFvalue); }

			printf("%f %f %f  ", par.h(), par.V(), par.tF());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_h(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_hVint(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_h(start1);
	par.set_Vint(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h          Vint         "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_h(start1 + ((double)i)*step1);
		par.set_Vint(start2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_Vint(start2 + ((double)j)*step2);
			printf("%f %f   ", par.h(), par.Vint());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_h(stop1); par.set_Vint(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_tFV(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	par.set_tF(start1);
	par.set_V(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#"); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#tF          V            "); res.print_label(); printf("\n");
	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_tF(start1 + ((double)i)*step1);
		par.set_V(start2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_V(start2 + ((double)j)*step2);
			printf("%f %f   ", par.tF(), par.V());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_tF(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_run_p(Par &inpar, Var &invar, double start, double stop, double step) {
	Var initV = invar;

	double A1 = 0.2;
	double A2 = -11./8.;
	double B2 = -5.5;
	double tFstart = -1.0;
	double tFstop = -1.3;
	double tFvalue = -0.3;

	Res res(N_VAR);
	RootGSL root(inpar, function, res);
	if(root.Solve(initV) != GSL_SUCCESS) { printf("First shot is not good.\n"); return; }
	Var old(*res.get_V());

	printf("#automatic_run_p, start %f, stop %f, step %f | ", start, stop, step); inpar.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#V          tF            eF      Vint      "); res.print_label(); printf("\n");
	fflush(stdout);

	initV = old;
	int LOOPS = int((stop-start)/step);
	if(LOOPS < 0) { LOOPS = -LOOPS; step = -step; }
	for(int i=0; i<=LOOPS; i++) {
		inpar.set_V(start + ((double)i)*step);
		inpar.set_Vint(A1*(start + ((double)i)*step));
		inpar.set_epsilonF(A2*(start + ((double)i)*step)+B2);
		if(inpar.V() > tFstart){ inpar.set_tF(0); }
		else if(inpar.V() > tFstop){ inpar.set_tF(abs(inpar.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
		else { inpar.set_tF(tFvalue); }

		printf("%f %f %f %f", inpar.V(), inpar.tF(), inpar.epsilonF(), inpar.Vint());
		initV.shake();
		if(root.Solve(initV) != GSL_SUCCESS) { printf("\n"); initV = old; fflush(stdout); continue; }
		root.print();printf("\n");
		initV.set(res.get_V());
		old.set(res.get_V());
		fflush(stdout);
	}
	printf("#end automatic_run_V\n\n\n");
	fflush(stdout);

	inpar.set_V(stop);
	invar = initV;
	return;
}

void automatic_2Drun_ptF(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	double A1 = 0.2;
	double A2 = -11./8.;
	double B2 = -5.5;

	par.set_V(start1);
	par.set_tF(start2);
	par.set_Vint(A1*start1);
	par.set_epsilonF(A2*start1+B2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#automatic_2Drun_ptF "); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#V          tF        eF      Vint         "); res.print_label(); printf("\n");
	//printf("%f %f %f %f", par.V(), par.tF(), par.epsilonF(), par.Vint());

	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_V(start1 + ((double)i)*step1);
		par.set_tF(start2);
		par.set_Vint(A1*(start1 + ((double)i)*step1));
		par.set_epsilonF(A2*(start1 + ((double)i)*step1)+B2);
		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_tF(start2 + ((double)j)*step2);
			printf("%f %f %f %f", par.V(), par.tF(), par.epsilonF(), par.Vint());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_V(stop1); par.set_tF(stop2); par.set_Vint(A1*stop1); par.set_epsilonF(A2*stop1+B2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_hp(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2, double tFstart, double tFstop, double tFvalue) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	double A1 = 0.2;
	double A2 = -11./8.;
	double B2 = -5.5;

	par.set_h(start1);
	par.set_V(start2);
	par.set_Vint(A1*start2);
	par.set_epsilonF(A2*start2+B2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#automatic_2Drun_hp "); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h          V            tF      eF       Vint       "); res.print_label(); printf("\n");

	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_h(start1 + ((double)i)*step1);
		par.set_V(start2);
		par.set_Vint(A1*start2);
		par.set_epsilonF(A2*start2+B2);

			if(par.V() > tFstart){ par.set_tF(0); }
			else if(par.V() > tFstop){ par.set_tF(abs(par.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
			else { par.set_tF(tFvalue); }

		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_V(start2 + ((double)j)*step2);
			par.set_Vint(A1*(start2 + ((double)j)*step2));
			par.set_epsilonF(A2*(start2 + ((double)j)*step2)+B2);

			if(par.V() > tFstart){ par.set_tF(0); }
			else if(par.V() > tFstop){ par.set_tF(abs(par.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
			else { par.set_tF(tFvalue); }

			printf("%f %f %f %f %f", par.h(), par.V(), par.tF(), par.epsilonF(), par.Vint());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_h(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}

void automatic_2Drun_ph(Par &par, Var &initV, double start1, double stop1, double step1, double start2, double stop2, double step2, double tFstart, double tFstop, double tFvalue) {
	Res res(N_VAR);
	RootGSL *root = new RootGSL(par, function, res);

	double A1 = 0.2;
	double A2 = -11./8.;
	double B2 = -5.5;

	par.set_V(start1);
	par.set_Vint(A1*start1);
	par.set_epsilonF(A2*start1+B2);
	par.set_h(start2);
	int LOOPS1 = int((stop1-start1)/step1+0.5); if(LOOPS1 < 0) { LOOPS1 = -LOOPS1+1; step1 = -step1; }
	int LOOPS2 = int((stop2-start2)/step2+0.5); if(LOOPS2 < 0) { LOOPS2 = -LOOPS2+1; step2 = -step2; }

	printf("#automatic_2Drun_hp "); par.print_verboten();
	printf("#init_p   "); initV.print(); printf("\n");
	printf("#h          V            tF      eF       Vint       "); res.print_label(); printf("\n");

	fflush(stdout);

	initV.shake();
	while(root->Solve(initV) != GSL_SUCCESS) { printf("# shot is not good.\n"); initV.shake(); return; }
	Var old(*res.get_V());

	for(int i=0; i<=LOOPS1; i++) {
		par.set_V(start1 + ((double)i)*step1);
		par.set_Vint(A1*(start1 + ((double)i)*step1));
		par.set_epsilonF(A2*(start1 + ((double)i)*step1)+B2);
		par.set_h(start2);
		if(par.V() > tFstart){ par.set_tF(0); }
		else if(par.V() > tFstop){ par.set_tF(abs(par.V()-tFstart)/abs(tFstop-tFstart)*tFvalue); }
		else { par.set_tF(tFvalue); }

		initV = old;
		initV.shake();
		if(root->Solve(initV) != GSL_SUCCESS) { continue; }
		old.set(res.get_V());
		initV = old;

		for(int j=0; j<=LOOPS2; j++) {
			par.set_h(start2 + ((double)j)*step2);

			printf("%f %f %f %f %f", par.h(), par.V(), par.tF(), par.epsilonF(), par.Vint());
			initV.shake();
			if(root->Solve(initV) != GSL_SUCCESS) { printf("\n"); fflush(stdout); continue; }
			root->print(); printf("\n");fflush(stdout);
			initV.set(res.get_V());
		}
		printf("\n");
		fflush(stdout);
	}
	par.set_h(stop1); par.set_V(stop2);
	printf("\n#END\n");
	fflush(stdout);

	return;
}


} // end of namespace case_PAM_Vtg
